FG Spreadshirt Swag
Page 1 of 2 12 Last
  1. #1

    Error only on creation of a new Character

    I'm getting an error, but only when I create a new character.
    [ERROR] Script execution error: [string "numLevel"]:9: attempt to index a nil value

    Here's the code on line 9.
    Code:
    	nodeChar.getChild("numProficiencyBonus").setValue(nLevel);
    I set some debug code to see if there was a value present, and there is. It's a number value, as expected...

  2. #2
    Zacchaeus's Avatar
    Join Date
    Dec 2014
    Location
    Scotland
    Posts
    20,805
    What ruleset? How are you creating the character? We need a bit more info I think.
    If there is something that you would like to see in Fantasy Grounds that isn't currently part of the software or if there is something you think would improve a ruleset then add your idea here https://www.fantasygrounds.com/featu...rerequests.php

  3. #3
    Quote Originally Posted by Zacchaeus View Post
    What ruleset? How are you creating the character? We need a bit more info I think.
    Custom ruleset built off CoreRPG. So far, all I've really done is create the character...

  4. #4
    I don't see "numLevel" on that line. Are you sure that's the right script?

    JPG

  5. #5
    Quote Originally Posted by Moon Wizard View Post
    I don't see "numLevel" on that line. Are you sure that's the right script?

    JPG
    That's the code within numLevel.

    Here's the complete code within the item numLevel.
    Code:
    function onFirstLayout()
    	onValueChanged();
    end
    function onValueChanged()
    	local nodeChar = window.getDatabaseNode();
    	local nLevel = nodeChar.getChild("numLevel").getValue();
    	--set Bonuses
    	nodeChar.getChild("numProficiencyBonus").setValue(nLevel);
    	nodeChar.getChild("numNonProficiencyBonus").setValue(math.floor(nLevel / 4));
    	nodeChar.getChild("numFamiliarBonus").setValue(math.floor(nLevel / 2));
    	nodeChar.getChild("numSpellcastingBonus").setValue(nLevel);
    
    	charManager.setSpells(nodeChar, nLevel);	--sets number of spell slots
    end
    The first line with .setValue(nLevel) is line 9...

  6. #6

  7. #7
    Quote Originally Posted by damned View Post
    Set a Default value of 0 in the field?
    I have, and added debug code which shows that default value.

  8. #8

  9. #9
    Quote Originally Posted by damned View Post
    Try get rid of

    Code:
    function onFirstLayout()
    	onValueChanged();
    end
    I tried that and got other errors, dealing with setting the number of spells of each level the character could cast, but I figured out a way around those, so I guess it's good now. Thank you.
    No clue why there was both a value and not...

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

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