PDA

View Full Version : using lua to access values on the charsheet



Kurald
May 21st, 2010, 14:47
Hi,

I have the following problem. I have an item on one tab of the charsheet and I want to use the value there in the onDrag routine of one item on another tab of the same charsheet.

It's the value of a "labeledstring" and it has a name and a source. How can I get the value of this item (or read from the source)?

Kurald
May 21st, 2010, 22:24
I have the solution. I use getDatabaseNode() and a number of getParent() calls to get where I want to.

Stitched
August 28th, 2010, 14:50
Can you expand on that (ie: the method)? I'm trying to do this right now to do a "if "race" = string then set value blah blah and would love to know how you grabbed the contents of a labeledstring.


I have the solution. I use getDatabaseNode() and a number of getParent() calls to get where I want to.

Kurald
August 30th, 2010, 20:34
I did something like:


function onDrag(button, x, y, draginfo)
local original = getValue(); -- save the original value
local characterNode = getDatabaseNode().getParent().getParent().getParen t(); -- get charsheet db node
local statsNode = characterNode.getChild("stats"); -- get stats db node
local thrustNode = statsNode.getChild("thrust"); -- get thrust damage db node
local swingNode = statsNode.getChild("swing"); -- get swing damage db node

local thrust = thrustNode.getValue(); -- read thrust damage
if thrust == nil then thrust = "" end

the number of getParent() depend on where the code is called. Try printing the node name or something like that first until you found the correct number of getParents()