PDA

View Full Version : Getting a node from node and string path



Varsuuk
February 14th, 2021, 03:44
Is there a better way to do what I am doing below?

Basically "getAttributePath()" simply takes an attribute ID like str, con, dex etc and puts together a string offset to the char node to point to the score. It already existed for a different need elsewhere and I decided to reuse my creation. Then I saw what I ended up with and it works - but looks clunky.

The getAttributePath gives me a string, I use databasenjode's getPath() which takes a node (nodeChar passed in) and an optional offset (the value I get from getAttrib...) BUT that returns a string not a node. So I then need to do findNode() to get back to node.

Is there another method that if given a node and a "path" that can concat and return the note referring to it?
Like a databasenjode.getNode(baseNod, sOffsetPathFromBaseNode)?



function getAttributePath(sAttributeCode)
return "clilist1." .. sAttributeCode .. ".p1"
end

...

function recalculateAttributeModifiers(nodeChar)
local sAttributePath = getAttributePath(
Interface.getString("attributes_strength_id"))
Character_SWWB.onAttributeScoreChanged(DB.findNode (
nodeChar.getPath(sAttributePath)))

sAttributePath = getAttributePath(
Interface.getString("attributes_intelligence_id"))
Character_SWWB.onAttributeScoreChanged(DB.findNode (
nodeChar.getPath(sAttributePath)))
... the other 4 attributes...

Trenloe
February 14th, 2021, 09:46
https://fantasygroundsunity.atlassian.net/wiki/spaces/FGCP/pages/996644582/DB#getChild

Varsuuk
February 15th, 2021, 06:36
GetChild - dunno what was thinking when went to darabasenode info page that night. Was looking for something with “node” in name but I DID remember there was another way cos thought I’d used it but I searched in code, again on “node” ... was a busy return from that :)