LUA ERROR:attempt to call a nil value
6 replies



07.12.17 05:59:34 am
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.
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.
Code:
1
2
3
4
5
6
7
8
9
10
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
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

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.
I code, therefore I exist.
@
EngiN33R:

Code:
1
2
3
4
5
6
7
8
9
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
sample.ads={}
addhook("minute","sample.ads.minute")
function sample.ads.minute()
msg("Welcome to CS2DCN Forum")
msg(" www.cs2dcn.com")
msg("Advertising Wanted")
end

What does
mean? Is this the only code you're loading? Does it work when using non-UTF text? It's very hard to debug code based on a smiley face.

I code, therefore I exist.
Hold up - you did something like this? Running 2 scripts that uses the same
sample.ads
table?Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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


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



