-
January 2nd, 2022, 20:03 #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);
-
January 2nd, 2022, 20:23 #2
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
-
January 2nd, 2022, 20:57 #3
-
January 2nd, 2022, 21:49 #4
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
I don't see "numLevel" on that line. Are you sure that's the right script?
JPG
-
January 2nd, 2022, 21:56 #5
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
-
January 3rd, 2022, 03:16 #6
Set a Default value of 0 in the field?
-
January 3rd, 2022, 03:23 #7
-
January 3rd, 2022, 03:28 #8
Try get rid of
Code:function onFirstLayout() onValueChanged(); end
-
January 3rd, 2022, 03:42 #9
-
January 3rd, 2022, 07:44 #10
Supreme Deity
- Join Date
- Mar 2007
- Posts
- 20,541
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