English Table - Number value lua error

5 replies
Goto Page
To the start Previous 1 Next To the start
Up
KenVo
User
Offline Off
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
addhook("join","nowjoin")
function nowjoin(id)
     PLAYERS[id].tmp = {img ={}}
end

addhook("leave","nowleave")
function nowleave(id,reason)
     if PLAYERS[id] and PLAYERS[id].tmp then
          freeimage(PLAYERS[id].tmp.img)
          PLAYERS[id].tmp = nil
     end
end

addhook("spawn","nowspawn")
function nowspawn(id)
     if PLAYERS[id].tmp.img.image then --ERROR here Attempt to index field 'img'(A number value)
          freeimage(PLAYERS[id].tmp.img)
     end
     PLAYERS[id].tmp.img = image("gfx/pvp" .. PLAYERS[id].PVP.. ".png",0,0,200+id)
end



I can't give the whole script because it's quite long and complicated, but I get the error whenever I spawn after I die except the first time I spawn on the server.

The
Code:
1
freeimage(PLAYERS[id].tmp.img)
in spawn hook still works even though I get the error, but I still want to fix it.
26.01.12 11:53:03 am
Up
kalis
User
Offline Off
try :
Code:
1
if PLAYERS[id].tmp.img then
26.01.12 04:35:59 pm
Up
KenVo
User
Offline Off
I think I tried that it doesn't work.
26.01.12 06:53:57 pm
Up
Informatixa
User
Offline Off
try:
Code:
1
if PLAYERS[id].tmp.img ~= nil then
IMG:http://img3.imageshack.us/img3/8939/29153.gif
IMG:http://img123.imageshack.us/img123/5111/6152sy7.jpg
Creation of server status image for Counter-Strike 2D (WebSite)
26.01.12 07:59:21 pm
Up
Flacko
User
Offline Off
user KenVo has written:
I think I tried that it doesn't work.


Wait, wait, wait... you're asking for help here, you shouldn't be saying stuff as "I think i tried" or "I think I did" or "I think it won't work".

Get your ass back to your lua script and try that three times to make sure it doesn't work.

Replace
Code:
1
if PLAYERS[id].tmp.img.image then

with
Code:
1
if PLAYERS[id].tmp.img then

as kalis said.
27.01.12 01:26:06 am
Up
KenVo
User
Offline Off
Haha man I was at school when I post that message, sorry. By the way that works !

I actually tried "PLAYERS[id].tmp.img = something" and not "PLAYERS[id].tmp.img", but I wasn't quite sure because I was really tired yesterday.

Thank you.
To the start Previous 1 Next To the start