PDA

View Full Version : Question about finding Children...



Blackfoot
November 30th, 2013, 05:05
I currently have a data structure that looks something like this:
senses.sight.bonus
and I have a small number of different sense related bits of info that are stored...
senses.sight.bonusmodifier
senses.sight.levels
then I have a number of different senses that I store these bits of data for... sight, hearing, smell... (the usual ones)
I'm trying to run a loop to search these senses to determine which sense I'm acting on currently...
I was trying to use some code that looked something like this:
for _,v in pairs(nodeSenses.getChildren()) dobut it seems I'm missing something important... is there a way to search for the middle bit of the data easily?

Trenloe
November 30th, 2013, 06:11
getChildren should return all of the children at the next level, and your code should return a dbnode for each value of v in the table.

How are you getting nodeSenses?

What isn't working for you?

Blackfoot
November 30th, 2013, 07:14
getChildren should return all of the children at the next level, and your code should return a dbnode for each value of v in the table.

How are you getting nodeSenses?

What isn't working for you?
I'm looking to obtain the names of the sense as a string... sorry, I wasn't clear about that part.
nodeSenses is coming through with the correct data... I can get it to return the value of senses.sight.bonus for example... the node gets passed to my function when it is called.
Ideally.. I'd like to convert the 'name' of 'v' to a string with something like...
local sSense = v; ... but obviously I need something to change v from an array to a string.

Trenloe
November 30th, 2013, 16:45
nodeSenses is coming through with the correct data... I can get it to return the value of senses.sight.bonus for example... the node gets passed to my function when it is called.
Which node in your database is nodeSenses actually pointing to? use nodeSenses.getNodeName to tell you.


Ideally.. I'd like to convert the 'name' of 'v' to a string with something like...
local sSense = v; ... but obviously I need something to change v from an array to a string.

If nodeSenses is pointing to .senses then you can use:

for _,v in pairs(nodeSenses.getChildren()) do
Debug.console("Name of dbnode from table = " .. v.getNodeNAme);
end
Open the console and see the names being populated there. Change the Debug.console command above to use v.getNodeName as you wish. The key thing here is that v is not an array (table in LUA terms) it is a database node - so use the usual databasenode operations on it: https://www.fantasygrounds.com/refdoc/databasenode.xcp

Blackfoot
November 30th, 2013, 17:05
Thanks. Your pointers and the link helped me find the right call to get what I needed.. it's working now.

for _,v in pairs(nodeSenses.getChildren()) do
local sLabel = v.getName();
if sLabel == "sight" then
linkPCSense(v, nodePS, "sight");

Trenloe
November 30th, 2013, 17:16
Looking at the <databasenode>.getChildren() function it mentions:

The child nodes are returned as databasenode objects in a table with keys corresponding to the names of the child nodes.
The keys mentioned here are the first value in the table "row", so perhaps you can use the key directly without having to use the v.getName function:

for k,v in pairs(nodeSenses.getChildren()) do
if k == "sight" then
linkPCSense(v, nodePS, "sight");
I'm not sure exactly what format the key (k) will be in (long or short DB format).

Blackfoot
November 30th, 2013, 17:30
That works too and a bit more efficiently... thanks again.