STAR TREK 2d20
  1. #1

    Join Date
    Mar 2009
    Location
    Lidingö, Sweden, Europe
    Posts
    368

    Best way of getting the current character node from any child of the node?

    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.
    Code:
    nDodgePenalty = math.abs(DB.getValue(nodeChar, "penalty.dodge", nil)) * -1

  2. #2
    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

  3. #3
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    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)

    Code:
    local sSplitNode = StringManager.split(sPath, ".")[1];
    local nodeChar = nil;
    if sSplitNode[1] and sSplitNode[2] then
    	nodeChar = DB.findNode(sSplitNode[1] .. "." .. sSplitNode[2]);
    end
    Last edited by Trenloe; May 30th, 2023 at 16:32.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  4. #4
    Quote Originally Posted by Trenloe View Post
    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)
    Quote Originally Posted by Moon-Wizard View Post
    * Reminders
    Use DB over databasenode API calls
    EDITED: changed getNodeName to getPath to avoid confusion
    Last edited by bmos; May 30th, 2023 at 20:42.

  5. #5
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    Quote Originally Posted by bmos View Post
    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!
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  6. #6
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,404
    Quote Originally Posted by bmos View Post
    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.
    Last edited by Trenloe; May 30th, 2023 at 16:37.
    Private Messages: My inbox is forever filling up with PMs. Please don't send me PMs unless they are actually private/personal messages. General FG questions should be asked in the forums - don't be afraid, the FG community don't bite and you're giving everyone the chance to respond and learn!

  7. #7

    Join Date
    Mar 2009
    Location
    Lidingö, Sweden, Europe
    Posts
    368
    Quote Originally Posted by Trenloe View Post
    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)

    Code:
    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!

  8. #8
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
DICE PACKS BUNDLE

Log in

Log in