DICE PACKS BUNDLE
Page 2 of 2 First 12
  1. #11
    Quote Originally Posted by Moon Wizard View Post
    You can't assume that getChild("<name>") will always return a node; which is where I'm guessing that the nil error is coming from. If that database node does not exist, then the getChild function will return nil; which will throw an error since you are then trying to call setValue on a nil value.

    Instead of this:
    local nLevel = nodeChar.getChild("numLevel").getValue();
    nodeChar.getChild("numProficiencyBonus").setValue( nLevel);
    nodeChar.getChild("numNonProficiencyBonus").setVal ue(math.floor(nLevel / 4));
    nodeChar.getChild("numFamiliarBonus").setValue(mat h.floor(nLevel / 2));
    nodeChar.getChild("numSpellcastingBonus").setValue (nLevel);

    Try this:
    local nLevel = DB.getValue(nodeChar, "numLevel", 0);
    DB.setValue(nodeChar, "numProficiencyBonus", "number", nLevel);
    DB.setValue(nodeChar, "numNonProficiencyBonus", "number", math.floor(nLevel / 4));
    DB.setValue(nodeChar, "numFamiliarBonus", "number", math.floor(nLevel / 2));
    DB.setValue(nodeChar, "numSpellcastingBonus", "number", nLevel);

    Also, if the prof/nonprof/familiar/spellcasting bonuses are always based on level, I would recommend not even storing in the database at all. Just pull the level information when you need it, and apply the calculation then. Possibly even adding a global script like CharManager, with functions like getLevel(nodeChar), getProfBonus(nodeChar), ...

    Regards,
    JPG
    I added the debug to put the value of numLevel in chat before the set value is called, and it displayed properly, but still threw the error at the first .setValue. numLevel existed as did it's default value, so I don't know why the error is thrown, unless they're being calculated on dfferent threads and there's no reconciliation? I know, I'm reaching.... I'll try DB. Is this a lua thing, or is it in the Developers Guide. A cursory search didn't turn up anything related...

    Not familiar with DB (database?)

    The way this game works, those values are always needed, and aren't automatically added to anything because circumstance determines when your character gets it and when they don't. I just produce the values and allow it to be added to the modifier stack.

  2. #12
    Trenloe's Avatar
    Join Date
    May 2011
    Location
    Colorado, USA
    Posts
    33,362
    Quote Originally Posted by bloodylemming View Post
    I added the debug to put the value of numLevel in chat before the set value is called, and it displayed properly, but still threw the error at the first .setValue. numLevel existed as did it's default value, so I don't know why the error is thrown, unless they're being calculated on dfferent threads and there's no reconciliation?
    As Moon Wizard mentioned - "You can't assume that getChild("<name>") will always return a node" - if you did some debug along the lines of Debug.console("Child numProficiencyBonus = ", nodeChar.getChild("numProficiencyBonus")); you'll probably see this being reported in the console as Child numProficiencyBonus = nil

    Like I've mentioned before - when you get nil errors you need to work out what is actually nil - and to do that you have to deconstruct the statement if you have multiple objects/functions in the statement. For example, one of your lines of code is: nodeChar.getChild("numProficiencyBonus").setValue( nLevel); - this is carrying out API calls on the nodeChar database node object, and on the database node object returned from nodeChar.getChild("numProficiencyBonus") - if either of these are nil you'll get the error you're seeing. So, deconstruct the line where the error is being reported to see what is actually nil - which is more than likely the getChild("<name>") API function mention by Moon Wizard - because the database node you're trying to access hasn't been created yet. Moon Wizard mentions using DB.setValue because it creates the child node if it doesn't exist - this API function is from the DB package (detailed in the Wiki development guide): https://fantasygroundsunity.atlassia...82/DB#setValue
    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!

  3. #13
    Quote Originally Posted by Trenloe View Post
    As Moon Wizard mentioned - "You can't assume that getChild("<name>") will always return a node" - if you did some debug along the lines of Debug.console("Child numProficiencyBonus = ", nodeChar.getChild("numProficiencyBonus")); you'll probably see this being reported in the console as Child numProficiencyBonus = nil

    Like I've mentioned before - when you get nil errors you need to work out what is actually nil - and to do that you have to deconstruct the statement if you have multiple objects/functions in the statement. For example, one of your lines of code is: nodeChar.getChild("numProficiencyBonus").setValue( nLevel); - this is carrying out API calls on the nodeChar database node object, and on the database node object returned from nodeChar.getChild("numProficiencyBonus") - if either of these are nil you'll get the error you're seeing. So, deconstruct the line where the error is being reported to see what is actually nil - which is more than likely the getChild("<name>") API function mention by Moon Wizard - because the database node you're trying to access hasn't been created yet. Moon Wizard mentions using DB.setValue because it creates the child node if it doesn't exist - this API function is from the DB package (detailed in the Wiki development guide): https://fantasygroundsunity.atlassia...82/DB#setValue
    Okay, so it's likely that numProficiencyBonus didn't exist, and since I was only testing the the end part, I wasn't finding the problem? That makes sense. Thank you both.
    Last edited by bloodylemming; January 3rd, 2022 at 19:12.

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