Page 1 of 1

Defect report: functions.lua:920

Posted: Sun Oct 28, 2012 12:16 pm
by Cindy
"attempt to index local 'skill_from_db' (a nil value)'

I tried to run a script (elfdaily2 ) to level alts, and it worked fine yesterday, croaked with the above message today. I suspect that a new skill my scout elf got at level 6 causes a nil return in the code below (the error appears to happen on the if condition line, most likely because its null from the first line?):

Code: Select all

	local skill_from_db = database.skills[_skillname];	-- read skill parameters from database

	-- check is skill has an aslevel in skills.xml
	if ( skill_from_db.aslevel ~= nil and
		 skill_from_db.aslevel > player.Level ) then
		cprintf(cli.yellow, "You need at least level %d to levelup skill %s. Your level is %d.\n",
		   skill_from_db.aslevel, _skillname, player.Level );
		return false;
	end
Happened on two different accounts on two different characters, both level6 and both scouts.

Re: Defect report: functions.lua:920

Posted: Sun Oct 28, 2012 12:19 pm
by Cindy
So debugged with:

Code: Select all

	local skill_from_db = database.skills[_skillname];	-- read skill parameters from database
	print(_skillname)
	-- check is skill has an aslevel in skills.xml
got:

SCOUT_SHOT
SCOUT_WIND_ARROWS
SCOUT_RANGED_WEAPON_MASTERY

Perhaps some defensive coding for skill_from_db == nil would be appropriate after the db lookup.

Re: Defect report: functions.lua:920

Posted: Sun Oct 28, 2012 12:26 pm
by Cindy
This is a temporary fix, but i think a better one is needed (one that considers the design of this function fully)

Code: Select all

	local skill_from_db = database.skills[_skillname];	-- read skill parameters from database
	print(_skillname)

	if (skill_from_db == nil) then return false end
	

Re: Defect report: functions.lua:920

Posted: Sun Oct 28, 2012 12:47 pm
by rock5
Good work on debugging it yourself. This has actually been around for a long time. It's one of the very many things I'm fixing in the upcoming version of the bot that I've been working on. :D Your fix should do nicely until the update.

Re: Defect report: functions.lua:920

Posted: Sun Oct 28, 2012 7:11 pm
by lisa
hmm wouldn't this do that anyway

Code: Select all

skill_from_db.aslevel ~= nil
because if skill_from_db is nil so would skill_from_db.aslevel be nil.

NVM i looked it up in the file, yeah needs a check for nil

Re: Defect report: functions.lua:920

Posted: Sun Oct 28, 2012 9:29 pm
by rock5
Yeah, you can't index a non table. So you can't do

Code: Select all

skill_from_db.aslevel ~= nil
unless skill_from_db is a table.

Re: Defect report: functions.lua:920

Posted: Mon Oct 29, 2012 5:37 pm
by Cindy
the first object, if its nil, then it generally doesnt have fields/members.. so the compiler would fail trying to resolve the field.

Re: Defect report: functions.lua:920

Posted: Sun Feb 24, 2013 11:57 am
by Cindy
This now has a new form, this time on line 1006:

.../rom/functions.lua:1006: attempt to index local 'skill_from_db' (a boolean value)


Seems to crash my warden character(s) this time.

Re: Defect report: functions.lua:920

Posted: Sun Feb 24, 2013 12:02 pm
by Cindy
my print debug got me:

WARDEN_THORNY_VINE

Re: Defect report: functions.lua:920

Posted: Sun Feb 24, 2013 12:06 pm
by rock5
Double check your skills names. You would get that error if one of them was spelled wrong. Sorry the error message wasn't more helpful.

Re: Defect report: functions.lua:920

Posted: Sun Feb 24, 2013 12:19 pm
by Cindy
I don't even have that skill in my profile. This is a fresh install of the bot from yesterday.

Re: Defect report: functions.lua:920

Posted: Sun Feb 24, 2013 12:45 pm
by rock5
You probably have "levelupSkills1To10" in your profile and it's misspelt in that function. The line to fix is 1079 of functions.lua

Code: Select all

								 [3] = { aslevel = 2, skillname="WARDEN_THORNY_VINE" },
should be

Code: Select all

								 [3] = { aslevel = 2, skillname="WARDEN_THORNY_VINES" },
Or if you don't really need or want to use levelupSkills1To10 then you can just remove it from your profile.

Re: Defect report: functions.lua:920

Posted: Sun Feb 24, 2013 12:48 pm
by Cindy

Code: Select all

								 [3] = { aslevel = 2, skillname="WARDEN_THORNY_VINE" },  

You are half right. The problem is skill name, but its in the fuctions.lua file :)

EDIT: Never mind, you found it also.