PDA

View Full Version : Should be an easy one



Veldehar
December 15th, 2009, 19:54
So, I've got these lovely little scripts that pull up racial resistances. They work great except for one little thing. When I create a new character, which doesn't yet have a race, all my racial checks are returning a nil value script error. Naturally, once I put a race in and reopen the character sheet, all is well.

What bit of code do I need to eliminate this error?

My current script looks like this:


function onInit()
life1temp = window.getDatabaseNode() .getChild("resistances.life.race");
life1temp.onUpdate = update;
update();
end
function update()
life1rr = window.getDatabaseNode() .getChild("resistances.life.race");
setValue(life1rr.getValue());
end


Veldehar the Lua Noob

joshuha
December 15th, 2009, 20:01
createChild
function createChild( [name], [type] )
Create, or if it already exists fetch, the specified child node under the current node.



Basically you can replace the getChild in the onInit with createChild and it will create the node if it doesnt exist yet and if it does it will return it instead.

Veldehar
December 15th, 2009, 20:25
Ahh! Great! Thank you much.

Foen
December 15th, 2009, 21:25
Just a quick caveat: createChild will only work if the user 'owns' the parent node. It will generally be fine in PC character sheets (the GM 'owns' everything and the player 'owns' their own characters) but it won't work so well on shared stuff, like a shared combat tracker, shared notes/items etc.

Just one to look out for in the future ;)

Stuart

Veldehar
December 15th, 2009, 22:32
Thanks for that heads up, Stuart. That would be frustrating if I headed down that path without knowing it, LOL.

Veldehar