PDA

View Full Version : Best way of getting the current character node from any child of the node?



peterb
May 30th, 2023, 15:04
Is there a way to get the current character node without having to "walk the tree", like "window.window.windowlist.window"?

I like to be able to write something like the code below from any child of the character node.

nDodgePenalty = math.abs(DB.getValue(nodeChar, "penalty.dodge", nil)) * -1

bayne7400
May 30th, 2023, 15:12
local nodeWin= DB.getChild(window.getDatabaseNode(),"...")

That is if that control is sitting in a windowlist under the top node. You can adjust the dots to move higher or not quite as high :)

Trenloe
May 30th, 2023, 16:05
Get the path string to some database node within the charsheet and then use something like the following.

In this code, sPath is the full dot seperated database path to something within the character sheet - you can get this with DB.getPath(databasenode)


local sSplitNode = StringManager.split(sPath, ".")[1];
local nodeChar = nil;
if sSplitNode[1] and sSplitNode[2] then
nodeChar = DB.findNode(sSplitNode[1] .. "." .. sSplitNode[2]);
end

bmos
May 30th, 2023, 16:19
you can get this with <databasenode>.getNodeName()Important to note that latest best practices are to not use functions embedded in databasenode objects like node.getPath() in favor of DB.getPath(node)

* Reminders
Use DB over databasenode API calls

EDITED: changed getNodeName to getPath to avoid confusion

Trenloe
May 30th, 2023, 16:22
Important to note that latest best practices are to not use functions embedded in databasenode objects like node.getNodeName() in favor of DB.getNodeName(node)
Thanks!

Trenloe
May 30th, 2023, 16:31
Important to note that latest best practices are to not use functions embedded in databasenode objects like node.getNodeName() in favor of DB.getNodeName(node)
Note - it doesn't appear that DB.getNodeName(node) is a documented API function (and it's not used in the latest test CoreRPG). DB.getName appears to be the replacement, but it's not documented yet. DB.getPath(node) can be used (based off current documentation). I've updated my example code above.

peterb
May 30th, 2023, 17:25
Get the path string to some database node within the charsheet and then use something like the following.

In this code, sPath is the full dot seperated database path to something within the character sheet - you can get this with DB.getPath(databasenode)


local sSplitNode = StringManager.split(sPath, ".")[1];
local nodeChar = nil;
if sSplitNode[1] and sSplitNode[2] then
nodeChar = DB.findNode(sSplitNode[1] .. "." .. sSplitNode[2]);
end

Nice! Thanks!

Moon Wizard
May 30th, 2023, 17:50
Yes, the correct API should be DB.getPath (for the full path) and DB.getName (for the local node name). [DB.getNodeName was an old name, replaced by DB.getPath.]

Regards,
JPG