PDA

View Full Version : Referencing values in local mode



Spyke
August 2nd, 2008, 19:03
I'm having difficulty with a script in my ruleset when in local mode where the fields aren't available from the campaign database. I've read through a number of threads, particularly:

https://www.fantasygrounds.com/forums/showthread.php?t=7248&highlight=getvalue+local

but I'm still stuck.

My function collects the values of dozens of number fields and sets the total in a points total field. It works fine in host mode, as the code can find the character sheet root node using window.getDatabaseNode(). However, as noted in the thread above, this returns nil in local mode.

So, presumably in local mode all the number fields are treated as unbound, as we don't have access to the database.

Is it still possible to get and set the values of the fields on the character sheet? I can't seem to find out how to either reference the database nodes or reference the controls themselves.

Example:

I have a numberfield with name = "strength_points" and source = "stats.strength_points". The control is in the sheetdata in a windowclass called "charsheet_main". My script is currently called from the tab control down the side of the character sheet, reacting to the onClickDown() event.

Everything I try returns a nil value, including:

window.getDatabaseNode().getChild("stats.strength_points").getValue()
DB.findNode("stats.strength_points").getValue()
strength_points.getValue()
window.strength_points.getValue()
charsheet_main.strength_points.getValue()

Any help would be much appreciated!

Edit:

Further investigation shows that I can get to any control on the current window (using window.controlname.getValue()), but the problem arises when I try to reference a control on a different window. Interface.findWindow() seems like it should help, but I've had no joy with it.

I have a top-level window called "charsheet", and subwindows containing the controls such as "main" and "notes". In local mode the datasources return null, which is probably why findWindow() isn't working.

Spyke

Foen
August 3rd, 2008, 06:29
Having looked through this post and the other one you refer to, I think the top level character sheet node isn't accessible. I think it may exist (because there is some database structure evident in nested controls) but it doesn't seem to be available programmatically (getDatabaseNode returns nil).

This is only a problem if the script in one sheet/tab needs to refer to data in another sheet/tab, or if you need to refer to data which isn't bound to a control. I don't think there are any easy answers, unless anyone else has cracked this particular issue?

Stuart

Spyke
August 3rd, 2008, 12:23
Thanks Stuart.

I've partially cracked this. You can access a root databasenode for local characters by using User.getLocalIdentities(), as outlined here (https://www.fantasygrounds.com/refdoc/User.xcp#getLocalIdentities). There may be a typo on the page as you get access to the node using the variable 'databasenode' rather than 'dbnode'. (See the way this is handled in the d20 ruleset in identityselection_list.lua.)

E.g. to print the "stats.strength" field for each of the local identities use:


local idtable = User.getLocalIdentities();

for n, v in ipairs(idtable) do
print (v.databasenode.getChild("stats.strength").getValue());
end
The problem I've not yet cracked is how to identify which of the local identities is the one I want. I can check a field like the character name, but there may be more than one identity with the same name. On top of that, until I've got the right node I can't access the name of the current sheet to check it, as that's on a different window. As far as I can see, the only time you can be sure you've identified the node is when it's first selected to open the character sheet (in identityselection_entry_base.lua for example), but even if you stored that somewhere you'd have problems if the user opened multiple characters.

Hmm. I could simply calculate and update the totals for all the local characters at once... but that would get slower as the number increases.

Spyke