PDA

View Full Version : [Minor Bug] <checked /> tag only works if sourceless



Spyke
August 15th, 2008, 11:03
With controls built on the default checkbox template you can add a <checked /> tag to indicate that the checkbox should be initialised in the 'on' state. However, this only works if the control is not bound to the database.

Where the checkbox has been set previously, of course, and recorded in the database, it correctly returns the previous state, but on creating a new character sheet, where the node has not yet been created, it is ignoring the <checked /> tag, and always initialising as 'off'.

To fix this, change the following fragment of code from the onInit() function in template_checkbox.lua, from:


-- Get value from source node
if sourcename then
source = window.getDatabaseNode().createChild(sourcename[1], "number");
else
source = window.getDatabaseNode().createChild(getName(), "number");
endto:


-- Get value from source node
if sourcename then
source = window.getDatabaseNode().createChild(sourcename[1], "number");
else
source = window.getDatabaseNode().createChild(getName(), "number");
if checked then
source.setValue(1);
end
end
Spyke

Foen
August 15th, 2008, 11:28
Good spot Spyke, please would you add it to the FG Fix List (https://www.fantasygrounds.com/forums/showthread.php?t=8194)?

Have a great weekend,

Stuart

Spyke
August 15th, 2008, 11:34
Done.

Stuart, should we post directly to the fix list, or is it still worth posting separately first?

Spyke

Foen
August 15th, 2008, 15:02
Thanks for that Spyke.

I'm easy either way on the posting: there isn't much comment generated by these things, but hopefully it should be an easy resource for SmiteWorks to draw from for future patches.

The fix list is also very useful for ruleset developers because it means there is a list of the things that need fixing in the d20 base ruleset before building new rulesets from it. That way the errors don't get dutifully copied over.

You can be sure I'll run through the fix list before finalising the forthcoming Call of Cthulhu and Rolemaster rulesets.

Cheers

Stuart