PDA

View Full Version : Problem with getChildren()



Fransiskos2
December 28th, 2017, 21:52
Hi

Can somebody help me with finding the error I am making?
I try to use the getChildren() function to get a table of targets. Due to the API(https://www.fantasygrounds.com/refdoc/DB.xcp#getChildren) the function should return a table, but I can't get it to work. What do I do wrong?

I have a node with 10 children. The node is the windowlist "targets" in ct_targets windowclass in the ct_host.xml and the children is ct_target windowclass. The first line(Debug...) prints #10, which corresponds to the targets shown in the combat tracker. But I never get into the while loop, it seems like the table is empty...

Debug.console(node.getChildCount());
local nodetable = {};
nodetable = node.getChildren();
local i = 1;
while nodetable[i] do
Debug.console("in while loop");
dblocal = nodetable[i];
name = dblocal.getNodeName();
print(name);
i = i + 1;
end

Thanks

Ikael
December 28th, 2017, 22:21
getChildren does not return you numerically indexed nodes, instead by nodename. Ie. You try to get index n value which never exists.

Try this iteration instead:

for _,nodeChild in pairs(node.getChildren()) do
print(nodeChild.getNodeName())
end

Fransiskos2
December 28th, 2017, 22:34
Perfect! - thanks a lot :)