PDA

View Full Version : Skill list deletion error



ThinkTank
December 28th, 2013, 02:46
Im having a problem identifying a lua script error. The script in question being charsheet_skill.

function onMenuSelection(selection, subselection)
if selection == 6 and subselection == 7 then
local node = getDatabaseNode();
if node then
local parentskillnum=DB.findNode(parentskill.getValue()) .getChild("subskillnumber");
parentskillnum.setValue(parentskillnum.getValue()-1);
node.delete();
else
local parentskillnum=DB.findNode(parentskill.getValue()) .getChild("subskillnumber");
parentskillnum.setValue(parentskillnum.getValue()-1);
close();
end
end

This section, in particular:

local parentskillnum=DB.findNode(parentskill.getValue()) .getChild("subskillnumber");
parentskillnum.setValue(parentskillnum.getValue()-1);

Is causing the error:

Script Error: [string "charsheet/scripts/charsheet_skill.lua"]:46: attempt to index local 'parentskillnum' (a nil value)

When attempting to delete a created skill list item from the list using the radial command.

Where should I be looking to fix this?

Trenloe
December 28th, 2013, 10:12
The error is telling you that the parentskillnum databasenode object is nil - i.e. local parentskillnum=DB.findNode(parentskill.getValue()) .getChild("subskillnumber"); doesn't return a databasenode object.

In your code is the space between DB.findNode(parentskill.getValue()) and .getChild("subskillnumber") actually present? If so, remove it so the line is local parentskillnum=DB.findNode(parentskill.getValue()) .getChild("subskillnumber");

If this doesn't work, you need to check that "parentskill" is valid at this point. Add the following line before parentskill is used to see if it is present (the information will be output to the console window, open this window by typing /console in the chat window):

Debug.console("parentskill.getValue() = " .. parentskill.getValue());

Then look in the console window to see what value is contained in parentskill. This will help you identify if the problem is the name of the db node held in parentskill or if parentskill is not actually available at this point (you'll get another "nil value" error but this time pointing to parentskill).

ThinkTank
December 28th, 2013, 17:16
Thanks, got it sorted out now.