English LUA ERROR:attempt to call a nil value

6 replies
Goto Page
To the start Previous 1 Next To the start
Up
sac op me
User
Offline Off
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.
Code:
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
IMG:http://steamsignature.com/status/default/76561198065995158.png
IMG:http://steamsignature.com/AddFriend.png
07.12.17 06:27:45 am
Up
Devil-Thanh
GAME BANNED
Offline Off
07.12.17 09:56:14 am
Up
EngiN33R
Moderator
Offline Off
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.
I code, therefore I exist.
07.12.17 04:29:12 pm
Up
sac op me
User
Offline Off
@user EngiN33R:
Code:
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

IMG:http://steamsignature.com/status/default/76561198065995158.png
IMG:http://steamsignature.com/AddFriend.png
08.12.17 12:23:32 pm
Up
EngiN33R
Moderator
Offline Off
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.
08.12.17 01:50:58 pm
Up
Cure Pikachu
User
Offline Off
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
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
IMG:https://i.imgur.com/DeSeUxC.png
IMG:https://i.imgur.com/xpsyQRX.png
14.12.17 01:51:43 am
Up
ImCloudy
User
Offline Off
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