Starfinder Playlist
  1. #1
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075

    Getting a "databasenode" from a databasenode and path string?

    If I get the "characterID" node (ie, like the "character root" of sorts) as an argument, what is the best way to access the NODE that is described by appending a path to that root?
    I have always gotten the VALUE of the node via DB.getValue(nodeChar, path, default) calls. But that returns a value not a databasenode.

    Here is one way I hit and missed to resolve:
    Code:
    local node = DB.findNode(nodeChar.getPath() .. ".abilities.strength.score");
    Any better way if the above is not the recommended way?
    (doing it this way for now and will recode if other solutions recommended)

  2. #2

  3. #3
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Yeah, I've used that and it should be the obvious one normally - but as you might be able to infer, the node given to me as an argument is already the "main character node" you get with getDatabasaeNode. I am trying to travel from that node to "ThatNode.abilities.strength.**score**"

    How do I do so with least amount of lookups or temporary node creation (if that's a thing, I'm C++ some Java not Lua...) to get where I am going.
    My first attempt also was to create a path from path of dynode + relative offset to where I want to go. Then parlay that into a reference to the node I always wanted to begin with.

    But seemed circuitous and figured there is another clearer way.
    Last edited by Varsuuk; March 16th, 2019 at 06:36.

  4. #4
    If nodeChar is valid then:

    DB.getValue(nodeChar,"abilities.strength.score",0);

    Seems easier? That returns the value you are trying to get (the strength score) or 0 if it's not set.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  5. #5
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    I'm actually trying to get the NODE itself (pointing to score in that string) not the value of the node.
    The line I posted works, but strikes me as "not quite elegant"

    I originally looked for something like (pseudo api): databasenode = myNode.childAt("path.to.child")

    Off to sleep (sorry if wasn't clear)

  6. #6
    Not really clear on your use case. Normally I'd use getDatabaseNode() from within the scope of the abilities windowclass (or a handler) and process whatever you're wanting. Otherwise I'd use the previously mention method to get the value.
    ---
    Fantasy Grounds AD&D Reference Bundle, AD&D Adventure Bundle 1, AD&D Adventure Bundle 2
    Documentation for AD&D 2E ruleset.
    Custom Maps (I2, S4, T1-4, Barrowmaze,Lost City of Barakus)
    Note: Please do not message me directly on this site, post in the forums or ping me in FG's discord.

  7. #7
    Ikael's Avatar
    Join Date
    Jan 2008
    Location
    Finland/Joensuu
    Posts
    2,384
    Code:
    local nodeStr = nodeChar.getChild("abilities.strength.score")
    Or if you want to make sure that the node exists and you know that the script it invoked by user who is owner of the nodeChar

    Code:
    local nodeStr = nodeChar.createChild("abilities.strength.score", "number")
    If the node already exists, this will function as getChild otherwise it will create the node and return it. If the script invoker is not owner, it will return nil.
    Last edited by Ikael; March 16th, 2019 at 10:47.
    "Alright, you primitive screwheads, listen up: THIS... is my BOOMSTICK!" -- Ash Williams, Army of Darkness

    Post your SavageWorlds ruleset feature requests and issue reports here!

  8. #8
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    OK... getChild(path) WHY did that not pop in my mind. I'd say I should stop coding at midnight to 2am except that is why I stopped working on my project - when I limited myself to non-existent free time in "normal hours"
    So that works to do what I was doing via the first post that my gut told me was unelegant - glad my "clunky-sense" is still working.


    Celestian, I already had the node that getDatabaseNode would give and your getValue would work to get the value of the node that I wanted to "point to" (I don't have words for describing lua concepts well yet) but I wanted to point to it to later "do things" with it In the end, I realized I was better off with the parent that you referred to via getDatabaseNode but I was and ever am curious and I wanted to know if there was another way to do it. That it was so obvious as getChild makes me shake my head at my not seeing it. Responders not getting what I meant I understand as it is common when I write questions, I'm not good at head to paper (as it were.)

    I actually look a bunch at your great code and saw that "node.getChild(....)" to go up levels, which at first made me... huh? until I realized there was no getParent() for multilevels up but there was for down or rather "delta" movement which includes up.

    (Rereading what I wrote... yeah, not clear - this is why I am trying to show code more when I ask.)

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
  •  
5E Product Walkthrough Playlist

Log in

Log in