FG Spreadshirt Swag
Page 1 of 2 12 Last
  1. #1

    Grabbing Data from another Window Within a Data List

    Hey all,
    I am continuing my journey to learn FG and I ran into another mystery. I created a simplied example to explain. So I have a window (test_main) with a window list (test_window_list). The list contains objects from testthing. I have a field on the test_main named test_number. Test number has a value of 1221456. example.JPG

    I added a button within the window list to grab the value of test_number. I keep on getting the default ZERO. Is there something I do differently within a window list?

    function onClickRelease(button, x, y)

    -- All the options I tried.
    --local CharNode = getDatabaseNode().getParent()-- Got DEFAULT OF ZERO **
    local CharNode = getDatabaseNode().getParent().getParent() -- Got DEFAULT OF ZERO
    --local CharNode = getDatabaseNode().getParent().getParent().getParen t() -- Got DEFAULT OF ZERO
    --local CharNode = getDatabaseNode().getParent().getParent().getParen t().getParent() --NIL VALUE ERROR!!!!!!!!!!!!! I went too deep!

    local sTest = DB.getValue (CharNode,"test_number",0)

    ChatManager.Message(sTest)

    end
    Daniel A George

  2. #2
    You'd have to have more information on where this object exist in the hierarchy relative to the base record you are trying to access. Unless you specify otherwise, subwindows use the same database node as the parent window.

    Have you tried something simple like this?
    Code:
    function onButtonPress()
        ChatManager.Message(DB.getValue(window.getDatabaseNode(), "test_number", 0);
    end
    Remember that database structure is independent of window/control layout structure.

    Regards,
    JPG

  3. #3
    That was my understanding as well. I tried your suggestion and and the chat shows zero still.

    I below is a link to the three files that make up the test page. They are VERY short. Still baffled.

    https://www.dropbox.com/scl/fo/jx9jg...04655izqy&dl=0

    Thanks. Still not drinking yet
    Daniel A George

  4. #4
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,420
    EDIT: sorry, I was looking at the wrong control. You're using the "number" template which, unless it's being changed, is a numberfield control in the CoreRPG ruleset - so it is storing data in the database. Sorry if you've already read my confusing response...

    Have you saved the campaign db.xml file (you can use the /save chat command) and checked what value is stored in the database? This will also help indicate the database hierarchy - look for <test_number type="number">123456</test_number> in the campaign db.xml file.
    Last edited by Trenloe; March 31st, 2024 at 01:39.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  5. #5
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,420
    When you open the test_main window, do you give it a datasource?
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,420
    Running a test with this, opening the test_main windowclass using the following chat command: /openwindow test_main testing gives this in the database (extra data removed for clarity):

    Code:
    <root>
    	<testing>
    		<test_number type="number">123456</test_number>
    	</testing>
    	<testthing>
    		<id-00001>
    			<name type="string">Test 1</name>
    			<talent_lnk type="windowreference">
    				<class>weapon</class>
    				<recordname />
    			</talent_lnk>
    			<weapon_calc type="number">0</weapon_calc>
    		</id-00001>
    	</testthing>
    	<treasureparcels />
    	<vehicle />
    </root>
    So, we can see that the base window uses the "testing" datasource (which I gave in the /openwindow chat command) but the "testthing" windowlist list uses a root "testthing", not withing "testing" - this is because the testthing windowlist datasource parameter is a root database reference, not a relative database reference.

    Changing this, which is the root database reference:
    Code:
    			<windowlist name="test_window_list">
    				<bounds>6,5,441,318</bounds>
    				<class>testthing_list</class>
    				<datasource>testthing</datasource>
    				<allowcreate />
    				<acceptdrop>
    					<class>testthing</class>
    					<field>*</field>
    				</acceptdrop>
    				<backcolor>#FFFFFFFF</backcolor>
    			</windowlist>
    To this, which is a relative database reference - note the dot (.) before testthing in the <datasource> parameter:

    Code:
    			<windowlist name="test_window_list">
    				<bounds>6,5,441,318</bounds>
    				<class>testthing_list</class>
    				<datasource>.testthing</datasource>
    				<allowcreate />
    				<acceptdrop>
    					<class>testthing</class>
    					<field>*</field>
    				</acceptdrop>
    				<backcolor>#FFFFFFFF</backcolor>
    			</windowlist>
    Will result in the "testthing" data to be nested in the "testing" database structure - which is what we want:

    Code:
    	<testing>
    		<test_number type="number">123456</test_number>
    		<testthing>
    			<id-00001>
    				<talent_lnk type="windowreference">
    					<class>weapon</class>
    					<recordname />
    				</talent_lnk>
    				<weapon_calc type="number">0</weapon_calc>
    			</id-00001>
    		</testthing>
    	</testing>
    So, in order to go from window.getDatabaseNode() in the windowlist (the <id-00001> entry in the example db above) requires going two levels up to be able to access "test_number". This is how I'd do that, using relative database notation of three dots - the first dot references id-00001 node and then the next two traverse up to the testing node - which has direct access to "test_number".

    Code:
    			<buttonfield name="weapon_calc">
    				<bounds>245,9,22,23</bounds>
    				<tooltip textres="testthing_list_weapon_calc_Tooltip" />
    				<allowdoubleclick />
    				<icon normal="recalc_button_base" pressed="recalc_button_click" hover="recalc_button_hover" />
    				<script>
    					function onClickDown(button, x, y)
    					
    					     ChatManager.Message(DB.getValue(window.getDatabaseNode(), "...test_number", 0));
    					    
    					end
    				</script>
    			</buttonfield>
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  7. #7
    That makes sense. Thanks. Learning how the data is stored is on my list to learn. THANK YOU all for the lesson. I can't wait to give this a try when I get back home. CHEERS!
    Daniel A George

  8. #8
    Sorry, was out of town. I cant seem to find where I edit "To this, which is a relative database reference - note the dot (.) before testthing in the <datasource> parameter:". Where is it?

    I FOUND IT. It tooks me a bit. I just did a wildcard search for datasource in all the xml files.
    Last edited by augustgames; April 6th, 2024 at 20:34. Reason: error
    Daniel A George

  9. #9
    So now when I bring up the list in Fantasy Grounds it is empty (just a white box).
    Capture.JPG

    SORRY I EDITED.

    So it did work! My exsiting text data was not there because I assume it did not update any exiting data. Once I added new records it worked it worked perfectly. Thanks.


    Thanks.
    Last edited by augustgames; April 6th, 2024 at 21:38.
    Daniel A George

  10. #10
    I have been applying what I learned here and have been able to pull values from numbers and text fields. What I am not able to pull is a value from a combo b (See code below). Is there anything else I need to do differntly when pullling from a combo box? If I assign a text field to be equal to the combo box I can pull the data. It's a work around, but still odd. Advice?


    Code:
    			<rsw_combobox name="weapon_type">
    				<frame offset="7,5,7,5" />
    				<bounds>25,111,112,18</bounds>
    				<font>sheettext</font>
    				<script>
    					function onInit()
    					
    					super.onInit();
    					add("Axe","Axe");
    					add("Brawl","Brawl");
    					add("Bow","Bow");
    					add("Crossbow","Crossbow");
    					add("Exotic Melee","Exotic Melee");
    					add("Exotic Ranged","Exotic Ranged");
    					add("Hammer","Hammer");
    					add("Light Blade","Light Blade");
    					add("Mace","Mace");
    					add("Shield","Shield");
    					add("Spear","Spear");
    					add("Sword","Sword");
    					add("Thrown","Thrown");
    					end
    					
    				</script>
    			</rsw_combobox>
    Daniel A George

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