Forum

> > CS2D > Scripts > LUA ERROR:attempt to call a nil value
Forums overviewCS2D overview Scripts overviewLog in to reply

English LUA ERROR:attempt to call a nil value

6 replies
To the start Previous 1 Next To the start

old LUA ERROR:attempt to call a nil value

sac op me
User Off Offline

Quote
The problem is the sample lua I've rewritten.
And this lua, I remember, seems to be working normally at 1.0.0.5.
So the question is a little puzzling.
It has nothing to do with utf-8.
1
2
3
4
5
6
7
8
9
10
if sample==nil then sample={} end
sample.ads={}

addhook("minute","sample.ads.minute")
function sample.ads.minute()
	msg("UTF-8:\x48\x6F\x74\x20\x53\x6E\x6F\x77\xE6\x88\x98\xE9\x98\x9F\xE6\x8B\x9B\xE6\x94\xB6\xE5\x90\x84\xE7\xB1\xBB\x32\x44\xE7\x8E\xA9\xE5\xAE\xB6")
	msg("UTF-8:\xE5\x8F\xAA\xE8\xA6\x81\xE4\xBD\xA0\xE7\x83\xAD\xE7\x88\xB1\xE5\xB9\xB6\xE6\x84\xBF\xE6\x84\x8F\xE5\x9D\x9A\xE6\x8C\x81\xE8\xBF\x99\xE4\xB8\xAA\xE6\xB8\xB8\xE6\x88\x8F\xEF\xBC\x8C\xE6\x88\x91\xE4\xBB\xAC\xE9\x9A\x8F\xE6\x97\xB6\xE6\xAC\xA2\xE8\xBF\x8E\xE4\xBD\xA0")
	msg("UTF-8:\xE5\x8A\xA0\xE5\x85\xA5\xE6\x88\x98\xE9\x98\x9F\xE8\xAF\xB7\xE8\xA7\x81\x32\x44\xE4\xB8\xAD\xE6\x96\x87\xE7\xBD\x91\xE6\x8B\x9B\xE6\x94\xB6\xE5\x90\xAF\xE7\xA4\xBA\xE8\xB4\xB4")
	msg("UTF-8:\xE5\xB9\xBF\xE5\x91\x8A\xE4\xBD\x8D\xE6\x8B\x9B\xE5\x95\x86\xEF\xBC\x8C\xE5\x92\xA8\xE8\xAF\xA2\xE8\xAF\xB7\xE8\xA7\x81\x32\x44\xE4\xB8\xAD\xE6\x96\x87\xE7\xBD\x91")
end

old Re: LUA ERROR:attempt to call a nil value

EngiN33R
Moderator Off Offline

Quote
user sac op me is right in that an "attempt to call a nil value" error would not be caused by UTF-8 text. If I had to guess I'd say that
sample.ads.minute
was somehow set to nil - if a hook gets added to a nonexistent function, you would expect to get this error.

Do you load any other scripts? On my copy of CS2D (latest live version) the code gets executed without issue.

old Re: LUA ERROR:attempt to call a nil value

sac op me
User Off Offline

Quote
@user EngiN33R:
1
2
3
4
5
6
7
8
9
if sample==nil then sample={} end
sample.ads={}

addhook("minute","sample.ads.minute")
function sample.ads.minute()
	msg("Welcome to CS2DCN Forum")
	msg("    www.cs2dcn.com")
	msg("Advertising Wanted")
end

old Re: LUA ERROR:attempt to call a nil value

Cure Pikachu
User Off Offline

Quote
Hold up - you did something like this? Running 2 scripts that uses the same
sample.ads
table?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
if sample==nil then sample={} end
sample.ads={}

addhook("minute","sample.ads.minute")
function sample.ads.minute()
     msg("UTF-8:\x48\x6F\x74\x20\x53\x6E\x6F\x77\xE6\x88\x98\xE9\x98\x9F\xE6\x8B\x9B\xE6\x94\xB6\xE5\x90\x84\xE7\xB1\xBB\x32\x44\xE7\x8E\xA9\xE5\xAE\xB6")
     msg("UTF-8:\xE5\x8F\xAA\xE8\xA6\x81\xE4\xBD\xA0\xE7\x83\xAD\xE7\x88\xB1\xE5\xB9\xB6\xE6\x84\xBF\xE6\x84\x8F\xE5\x9D\x9A\xE6\x8C\x81\xE8\xBF\x99\xE4\xB8\xAA\xE6\xB8\xB8\xE6\x88\x8F\xEF\xBC\x8C\xE6\x88\x91\xE4\xBB\xAC\xE9\x9A\x8F\xE6\x97\xB6\xE6\xAC\xA2\xE8\xBF\x8E\xE4\xBD\xA0")
     msg("UTF-8:\xE5\x8A\xA0\xE5\x85\xA5\xE6\x88\x98\xE9\x98\x9F\xE8\xAF\xB7\xE8\xA7\x81\x32\x44\xE4\xB8\xAD\xE6\x96\x87\xE7\xBD\x91\xE6\x8B\x9B\xE6\x94\xB6\xE5\x90\xAF\xE7\xA4\xBA\xE8\xB4\xB4")
     msg("UTF-8:\xE5\xB9\xBF\xE5\x91\x8A\xE4\xBD\x8D\xE6\x8B\x9B\xE5\x95\x86\xEF\xBC\x8C\xE5\x92\xA8\xE8\xAF\xA2\xE8\xAF\xB7\xE8\xA7\x81\x32\x44\xE4\xB8\xAD\xE6\x96\x87\xE7\xBD\x91")
end

if sample==nil then sample={} end
sample.ads={}

addhook("minute","sample.ads.minute")
function sample.ads.minute()
     msg("Welcome to CS2DCN Forum")
     msg("    www.cs2dcn.com")
     msg("Advertising Wanted")
end

old Re: LUA ERROR:attempt to call a nil value

ImCloudy
User Off Offline

Quote
Simply never ever use already existing function names, that's why people tags their functions by <project.group.name> or similar kind of naming.
Anyway I don't see any problems with the code posted here. And when you duplicate function name, it should destroy both to make the game throw a nil error. Check the coding of your file (ANSI, UTF8, ...) Maybe there's some invisible character which cs2d can't parse and then it does undefined behaviour.

Good luck with your problem solving.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview