FG Spreadshirt Swag
Page 1 of 2 12 Last

Thread: Databasenodes

  1. #1

    Databasenodes

    And its me again....

    I still dont get it right

    I do have a field on the charsheet called "useedge" this is a Checkboxfield (it can have the values 0 or 1
    in the db.xml it is saved "<useedge type="number">0</useedge>"
    it is directly under <charsheet> <id-0001>

    I am in the Chat_chat.lua and i need the Value of that specific field. How do i get it.

    I tried

    local v1 = 0;
    v1=window.useedge.getValue()

    (and some other stuff)
    (error: attempts to index field "useedge" (a nil value), the Value in the Database is 1 though)


    If i have understood the Syntax correctly, then the variable useedge is found in the actual window (charsheet with id-0001, that is where i am at that moment)

    If the Char is named "player1"
    and If i would be in the Combattracker

    how would i then get that useedgevalue?

    I am a bit confused, because of those errormessages

  2. #2
    The checkbox is a special template control that can generate a databasenode to store a number value. However, that means a getValue() isn't going to automatically return the database value as the control itself isn't a data field. What you have to do is essentially get the databasenode yourself.

    How you reference it depends on where you are.
    If you were on the character sheet itself you could do.
    window.getDatabaseNode().getChild("useedge").getVa lue()

    Normally if you are using a player on a combat tracker you are storing a link somewhere back to their db node ("charsheet.id-0001"). And then it would be nodelinkvariable.getChild("useedge").getValue() or alternatively DB.findNode("charsheet.id-0001.useedge").getValue()

  3. #3
    First of all, thanks for the answer!

    I am on the Charsheet atm, making a Dicerolle via Drag.
    I tried window.getDatabaseNode().getChild("useedge").getVa lue()

    but i still get an error:

    "attempt to index a nil Value"


    window refers to the actual Window i am on (charsheet.id-0001)

    getDatabaseNode() gets a nodepoint, but what nodepoint?


    getChild("useedge") i do understand it puts up the field "useedge".
    I thought though, that it gets the Value already of that field.

    I am still confused

    The Date in the DB.xml reads like this:
    Code:
    <root version="2.2">
    	<charsheet>
    		<id-00001>
                                 <useedge type="number">1</useedge>
    The problem is, that several people say several things and actually none worked so far and i am not sure why. *sigh*

    Fenloh

  4. #4
    Foen's Avatar
    Join Date
    Jan 2007
    Location
    Suffolk, England
    Posts
    2,007
    You might want to try some debug code using the console:
    Code:
    if getDatabaseNode() then
      print(getDatabaseNode().getNodeName());
    else
      print("Database Node not found!");
    end
    That will either tell you the database node isn't available from your context (say an unbound control) or will give you the full path of the current context. From the full path, you should be able to work out the way to access your useedge node.

    If you haven't used the console before, you can open it from within FG by typing /console.

    Hope that helps

    Stuart

  5. #5
    Well it did help, at least to understand what happens

    I found out, that from the chat_chat.Lua, where i am, i am actually not on the Charsheet anymore.. my bad that is.

    Now, how do i get the Information i need from the Charsheet where i drag my Dice from to the chat (thats the name of the node atm)?

    I know where the Info is that i want, i just cant find the right way to retrieve it.

  6. #6
    Foen's Avatar
    Join Date
    Jan 2007
    Location
    Suffolk, England
    Posts
    2,007
    You need to create a custom data object and attach it to the drag data. I suggest you place the full node path string in the custom data and then you can use DB.findNode(path) from within the chat_chat script to retrieve a reference to the node.

    Hope that helps

    Stuart

  7. #7
    Foen's Avatar
    Join Date
    Jan 2007
    Location
    Suffolk, England
    Posts
    2,007
    Custom data is used to pass information from a drag operation to the onDrop handler or the onDiceLanded handler. The dragdata structure is documented in the library here, but the following example should help.

    It works something like this:
    Code:
    onDrag function
    function onDrag(button,x,y,dragdata)
      ... other stuff ...
      local mydata = {};
      mydata.nodename = getDatabaseNode().getNodeName();
      dragdata.setCustomData(mydata);
      ... other stuff ...
    end
    Code:
    onDiceLanded or onDrop
    function onDiceLanded(draginfo)
      local mydata = draginfo.getCustomData();
      if mydata and mydata.nodename then
        print(mydata.nodename);
      end
    end
    Hopefully that should give you some pointers.

    Cheers

    Stuart

  8. #8
    Well thanks a lot for the Infos, they did help a bit.

    One thing is strange. Even if i do have the correct Datanodes i cannot get the data from the Database. I can see them in the dm.xml, but i cant get to them.

    e.g. I have a field woundmodifier on the same "window" I can receive the Data through "windows.woundmodifier.getValue()" in the db.xml there is no woundmodifier, there is a <stat><wound><modifier>2....

    Well i am puzzeld because i thought the databasenodes are directed to the db.xml.

    through the draginfo help i did get the needed data to the Chat_chat_lua and the code looks like this now:

    Code:
    function onDiceLanded(draginfo)
    	
    	if ChatManager.getDieRevealFlag() then
    		draginfo.revealDice(true);
    	end
    
    	if draginfo.isType("dice") then
    		local aretens=true;
    		for i = 1, draginfo.getSlotCount() do
    			draginfo.setSlot(i);
    			dicelist  = draginfo.getDieList();
    			local edgeuseage =0;
    			edgeuseage=draginfo.getCustomData();
    			
    			
    			
    			local entry = {};
    			entry.font = "sheetlabel";
    			
    			if dicelist then
    				local dicecount=table.maxn(dicelist);
    				local successes=0;
    				local failures=0;
    				local glitch = "leer";
    				local halfdice=0;
    				local explodetable = {};
    				local explodecount=0;
    				
    				
    			
    					print(edgeuseage);
    				for c = 1, dicecount do
    					if dicelist[c].type == "d6" then
    						if dicelist[c].result==6 and edgeuseage>=1 then
    							successes=successes+1;
    							explodecount=explodecount+1
    							table.insert(explodetable, "d6");
    						elseif dicelist[c].result>= 5 then
    							successes=successes+1;
    						elseif dicelist[c].result ==1 then
    							failures=failures+1;
    											
    						end
    						
    					else
    						aretens = false;					
    					end
    				end
    					if explodetable then
    					local explodedescription = "Exploderoll";
    						throwDice("dice", explodetable, 0, explodedescription);
    					end
    				
    
    				halfdice = math.ceil(dicecount/2)
    				if halfdice <= failures then
    					glitch = "Glitch";
    				end
    				if halfdice <= failures and successes == 0 then
    					glitch = "Critical Glitch";
    				end
    				if glitch == "leer" then
    				entry.text = draginfo.getDescription() .. "                                                                                     Successes: (" .. successes .. ")";
    				end
    				if glitch == "Glitch" then 
    				entry.text = draginfo.getDescription() .. "                                                                           Successes: (" .. successes .. ")" .. "                                                                              " .. glitch;
    				end
    				if glitch == "Critical Glitch" then
    				entry.text = draginfo.getDescription() .. "                                                                                    " .. glitch;
    				end 
    				if explodecount>0 then
    				entry.text=entry.text .. "                                                                                                Exloded Dice: (" .. explodecount .. ")";
    				end
    				if draginfo.getDescription()=="Exploderoll" then
    				entry.text = draginfo.getDescription() .. "                                                                            Successes: (" .. successes .. ")                                                                                     add succsesses to previous roll";
    				end
    				if User.isHost() then
    					entry.sender = GmIdentityManager.getCurrent();
    				else
    					entry.sender = User.getIdentityLabel();
    				end
    			else
    					entry.text = "No dice left roll.";
    			end
    			
    			if aretens then
    					
    					draginfo.setDescription(entry.text);
    					ModifierStack.reset();
    			
    			end
    		end
    	end
    end
    my Problem here is, that if a second "explosion" happens edgeuseage is a nil Value and i get an error. This happens begause the draginfos customdata is gone with the exploding wole.

    any Ideas?

    Fenloh

  9. #9
    You are trying to make it so a player can check of a Use Edge type checkbox and apply the Shadowrun rules right? I have something like this already written if you want I can give you the code so you can see how I did it.

  10. #10
    that would be great!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
STAR TREK 2d20

Log in

Log in