PDA

View Full Version : Grabbing Data from another Window Within a Data List



augustgames
March 30th, 2024, 05:48
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. 60413

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

Moon Wizard
March 30th, 2024, 06:01
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?


function onButtonPress()
ChatManager.Message(DB.getValue(window.getDatabase Node(), "test_number", 0);
end


Remember that database structure is independent of window/control layout structure.

Regards,
JPG

augustgames
March 30th, 2024, 14:43
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/jx9jg8z2i9uh1crh6a3ql/h?rlkey=kmhlgrjeg42w38qy04655izqy&dl=0

Thanks. Still not drinking yet :)

Trenloe
March 31st, 2024, 01:21
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.

Trenloe
March 31st, 2024, 01:38
When you open the test_main window, do you give it a datasource?

Trenloe
March 31st, 2024, 05:02
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):


<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:

<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:


<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:


<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".


<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.getDatabase Node(), "...test_number", 0));

end
</script>
</buttonfield>

augustgames
March 31st, 2024, 06:40
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!

augustgames
April 6th, 2024, 20:27
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.

augustgames
April 6th, 2024, 21:31
So now when I bring up the list in Fantasy Grounds it is empty (just a white box).
60476

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.

augustgames
April 6th, 2024, 23:23
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?



<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>

Moon Wizard
April 7th, 2024, 23:40
Just for additional information,
* If you don't apply the second parameter to the add function, it will just default to using the first one as well, so no need to specify twice.
* It's probably best to load these into a global script (usually DataCommon in many of the existing rulesets) as a table you can pull these values from, instead of hard-coding within the control. Easier for long-term maintenance.

Regards,
JPG