Forum

> > CS2D > Scripts > Table - Number value lua error
Forums overviewCS2D overview Scripts overviewLog in to reply

English Table - Number value lua error

5 replies
To the start Previous 1 Next To the start

old Table - Number value lua error

KenVo
User Off Offline

Quote
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
1
freeimage(PLAYERS[id].tmp.img)
in spawn hook still works even though I get the error, but I still want to fix it.

old Re: Table - Number value lua error

Flacko
User Off Offline

Quote
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
1
if PLAYERS[id].tmp.img.image then
with
1
if PLAYERS[id].tmp.img then
as kalis said.

old Re: Table - Number value lua error

KenVo
User Off Offline

Quote
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
Log in to reply Scripts overviewCS2D overviewForums overview