PDA

View Full Version : Need help debugging my skills script



meathome
November 20th, 2008, 15:04
Solved evrything i wrote about before... but new things keep kreeping up...
Now i have a strange behavior. when i first create a new character then

window.windowlist.window.windowlist.window.getData baseNode().getChild("abilities."..statname..".modifier")

returns null but if i close the sheet and reopen it evryithing works like it should.
Does anyone have an idea why this happens?

Foen
November 21st, 2008, 06:18
I think it might depend on the order in which controls are rendered and whether that database node has been instantiated at the time the code is looking for it.

You could try using createChild("abilities."..statname..".modifier","number") which will create the node if it doesn't exist or re-use the existing node if it does.

Foen

meathome
November 21st, 2008, 12:20
this gets rid of the error message, but first time i open the sheet, thelink to the attributes isnt working. only after i close and reopen the sheet does it work. :( edit : is there a way to force the order nodes are created in? i dont understand why the nodes dont exist. the abilities are created on the main sheet and its the first that is displayed, on it they are the first controls. Could it be that it is because i use nested windowlists? the first window. is to get to the windowclass of the inner list item windowlist.window from there is to get me to the windowclass containing that windowlist wich is used by another windowlist az item, from there windowlist.window should get me to the the windowclass containing that windowlist wich is the sheet itself. From there i call the getChild or createChild to get the abilities part wich are in the topmost level of the sheet.

Foen
November 21st, 2008, 13:05
A sheet renders (and controls are created) in roughly the same order as they appear in the XML. Generally, for nested controls, the innermost controls are initialised before the outermost ones, and that is certainly the order in which the onInit calls are made. Subwindows are a different case, as they seem to be instantiated after the containing window has been initialised, and you typically need to use the onInstanceCreated event to catch that.

A potentially pertinent point is the fact that FG doesn't create database nodes for controls which have the default values (zeroes for numbers, or blank strings). I am not certain whether those nodes exist virtually (in the in-memory copy of the database tree) and are just not saved to the physical DB, or whether they are missing entirely.

When you say the link isn't working, what link do you mean? Are you using onUpdate (for a database node) or onValueChanged?

Foen

meathome
November 21st, 2008, 13:36
heres the code:

local abilitymod;

function onInit()
statname=string.lower(window.stat.getDatabaseNode( ).getValue());


abilitymod = window.windowlist.window.windowlist.window.getData baseNode().getChild("abilities."..statname..".modifier");

print(abilitymod.getNodeName());
abilitymod.onUpdate=modifierSourceUpdated;
end



function modifierSourceUpdated()
setValue(abilitymod.getValue());
end

this code is in the script block of windowclass used for items in the inner windowlist

and on the main sheet the abilitys are numberfields where i set the source value tho abilites.statname.modifier etc.

Foen
November 21st, 2008, 14:26
If you use createChild, the code above should invoke your setValue() method whenever the ability modifier database node changes.

Note that there is a distinction between onUpdate (used above) and onValueChanged (used for many linked controls). onValueChanged is invoked whenever the control value changes, even if the control still has the focus. onUpdate is only invoked when the underlying database node is updated, which usually only happens when the control loses the focus. You may therefore see a delay between changing an ability mod and it being reflected in the linked field.

Although this is a pain, the fact that you can set the onUpdate handler from another control but cannot set the onValueChanged handler more than compensates for this.

Foen

meathome
November 23rd, 2008, 05:37
Thanks solved it the problem was actually that the stat field wasnt set at the time onInit() was called. Another thing wats the easiest way of accomplishing a list with ellements (the list and elements are static and dont need to be able to change )that are arrenged like this


item
+------item
+ +--------item
+ +-------------item
+-------item
+---------item
+
+---------item
+------------item

etc.

Foen
November 23rd, 2008, 06:21
That kind of variable-level nesting ins't easy, and I haven't done it myself, but I think Tenian did something very similar here (https://www.fantasygrounds.com/forums/showthread.php?t=8895) where he wanted to nest sections within articles, within chapters.

Foen