5E Product Walkthrough Playlist
  1. #1
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075

    Correct way to get sibling numeric data and add them in sheetdata

    [SOLVED]

    Going to head to sleep, this may be a dumb question that will become clearer with a night's sleep but here goes:

    Other than by fully qualifying from getDatabasenode() sort of level, is there a way to access a sibling's numeric data? ie, the value that would be returned with getValue() if we were in that control at the time?
    l
    If I have 3 number controls in a sheet data section and I wish to make controlC value = controlA value + controlB value, what is the way I would do this in the <script>onInit()</script> section for controlC?

    controlA's source is foo.a
    controlB's source is foo.b
    controlC's source is foo.c

    in controlC's script section...
    l
    Code:
      <script>
        function onInit()
          setValue(DB.getValue("..", "a", 0) + DB.getValue("..", "b", 0));
        end
      </script>
    The console reports: "attempt to perform arithmetic on string value"
    All three controls derive from "basic number".

    I know it isn't an adding of string + number thing - if I just got database node and did get value off that node with "foo.a" as a param added to another get of db node with "foo.b" as the param - the numbers would add up.

    So I am looking for basically the right way to inside the script of a control retrieve the values of sibling (or more generally other nodes using relative pathing)
    It is killing me as I reread this that the answer will be obvious once someone explains it... but it is nearly 4am for me so... go figure
    Last edited by Varsuuk; March 16th, 2019 at 05:33.

  2. #2

  3. #3
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Quote Originally Posted by damned View Post
    the actual error message is saying that the lookup data is string and you are trying to do math on it...
    Like I said, I think my attempt at accessing the siblings is off. I will try to look through code to find something similar in referencing. I am sure my problem is that what I THINK I am referencing in getValue(".." ...) is NOT what I expect, e.g.: DB.getValue(window.getDatabaseNode(), ...)

    I was trying to learn the "best" way to reference the field whether I need to use absolute or not referencing. ".." seems more elegant to me but didn't work.

    Code:
    ...
    <number_attribute_base name="adjusted_str_score" source="abilities.strength.score">
    ...
    this succeeds:
    
      setValue(DB.getValue(window.getDatabaseNode(), "abilities.strength.basemanualmod", 0) + DB.getValue(window.getDatabaseNode(), "abilities.strength.score", 0));
    
    this doesn't:
      setValue(DB.getValue("..", "abilities.strength.basemanualmod", 0) + DB.getValue("..", "abilities.strength.score", 0));

  4. #4
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    Btw, not asking exactly to “fix” what I wrote how I wrote it as much as suggest the right way (efficiency/elegance) in case I was going completely in the wrong direction and it should have been done in an entirely different manner.

    The first post describes what I was trying to do, have a third field at same “level” on sheet/xml reference two other fields for its value.

  5. #5
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    On my commute, I saw that Celestian does a similar thing only he does it in a separate script that looks at all 6 stats one at time. This may be a better way (and incidentally is a way that requires the full path since it starts with the char
    node not at the current leaf.) I will look at it later tonight to mine it for ideas. Should I not have gone that way, still interested in what I should do above.

    If no one sees it before I can run it, I will add some debugs to print the name of what node I am at when in script block for a control so I see if that is the basis of my mistake, that no matter what control's script I am in, I am considered to be at charsheet.item-0001 or something. That there is no "this position" or "current node" concept - with is probably my problem.

  6. #6
    Varsuuk's Avatar
    Join Date
    Dec 2015
    Location
    New York
    Posts
    2,075
    [SOLVED]

    I figured it out. I was away from this stuff nearly a year and forgot some things (although I am "getting it" more I think on this read than last)
    From the script scope section of: https://www.fantasygrounds.com/modguide/scripting.xcp


    This led me to:
    setValue(window.strength_base.getValue() + window.str_base_manual_mod.getValue());

    Which works. As I said, I realized after finding other ways this was handled in 5E and AD&D, I decided I would do it another way. That said, I am pigheaded about understanding things so I keep at it.

    I had tried "strength_base.getValue()" and received nil error, I did not think to go one more level. THAT'S IT - I AM PRINTING THIS PAGE (see above) AND TAPING IT TO MY DESK! - it is THAT useful
    Thanks for the advice, hopefully this answer might help someone when it is appropriate to use it this way.

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
  •  
STAR TREK 2d20

Log in

Log in