Forum

> > CS2D > Scripts > why error? a nil value
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch why error? a nil value

15 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt why error? a nil value

kalis
User Off Offline

Zitieren
here my code :
i leave cs2d 2, 3 week ! help me @ @
i want remove some image near player:
Error :
1
attempt to perform arithmetic on filed '?' (a nil value)
Lua :
create image
1
2
3
4
5
6
7
8
9
function create_light(l_x,l_y)
	if l_x and l_y then
		i = i + 1
		save_x[i] = l_x
		save_y[i] = l_y
		l_img[i] =  image("gfx/sprites/flare3.bmp",save_x[i],save_y[i],1)
		imagepos(l_img[i],save_x[i],save_y[i],math.random(1,360))
	end
end

remove image
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
addhook("attack","remove")
function remove(id)
	if id ~= nil then
		remove_light(id)
	end
end




function remove_light(id)
	local x = player(id,"x")
	local y = player(id,"y")
	if i then
		if x < (save_x[i] + 16) and x > (save_x[i] - 16) then
			if (y < save_y[i] + 16) and y > (save_y[i] - 16) then
				if l_img[i] ~= nil then
					save_x[i] = nil
					save_y[i] = nil
					freeimage(l_img[i])
				end
			end
		end
	end
end

alt Re: why error? a nil value

EngiN33R
Moderator Off Offline

Zitieren
But that's not an error connected with math functions, it's connected with tables.

Was the line where the error occurred specified? If so please provide that line from the code.

alt Re: why error? a nil value

DannyDeth
User Off Offline

Zitieren
@EngiN33R:
Just saw it. Didn't read the error message properly. Anyway, it means that a field of a table doesn't exist, but you are trying to use it. This will take a while to debug.

alt Re: why error? a nil value

Yasday
User Off Offline

Zitieren
"i" is used for the "save_x" and "save_y" table.
1
2
... (save_x[i] - 16) ...
... (save_y[i] - 16) ...
Could you show us the whole code and tell us what it's expected to do?

alt Re: why error? a nil value

EngiN33R
Moderator Off Offline

Zitieren
@Yasday

user kalis hat geschrieben
1
2
3
4
5
6
7
8
9
function create_light(l_x,l_y)
	if l_x and l_y then
		i = i + 1
		save_x[i] = l_x
		save_y[i] = l_y
		l_img[i] =  image("gfx/sprites/flare3.bmp",save_x[i],save_y[i],1)
		imagepos(l_img[i],save_x[i],save_y[i],math.random(1,360))
	end
end

alt Re: why error? a nil value

kalis
User Off Offline

Zitieren
i want make it like minecraft
make a light in somethings and remove it with hook "attack" (but player must near it)
here full code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
save_x = {}
save_y = {}
l_img = {}

l_x = {}
l_y = {}
local i

addhook("say","hehe")
function hehe(id,txt)
	if i == nil then
		i = 0
	else
		i = i
	end
	if txt == "test" then
		l_x = player(id,"x")
		l_y = player(id,"y")
		create_light(l_x,l_y)
	end
end

function create_light(l_x,l_y)
	if l_x and l_y then
		i = i + 1
		save_x[i] = l_x
		save_y[i] = l_y
		l_img[i] =  image("gfx/sprites/flare3.bmp",save_x[i],save_y[i],1)
		imagepos(l_img[i],save_x[i],save_y[i],math.random(1,360))
	end
end

addhook("attack","remove")
function remove(id)
	if id ~= nil then
		remove_light(id)
	end
end




function remove_light(id)
	local x = player(id,"x")
	local y = player(id,"y")
	if i then
		if x < (save_x[i] + 16) and x > (save_x[i] - 16) then
			if (y < save_y[i] + 16) and y > (save_y[i] - 16) then
				if l_img[i] ~= nil then
					save_x[i] = nil
					save_y[i] = nil
					freeimage(l_img[i])
				end
			end
		end
	end
end
any one reply ?
1× editiert, zuletzt 01.09.11 13:53:17

alt Re: why error? a nil value

kalis
User Off Offline

Zitieren
still error man =.=
i changed and still error
1
attampt to perform arithmetic on field '?' (a nil value)

alt Re: why error? a nil value

DannyDeth
User Off Offline

Zitieren
Testing the script... I get no errors whatsoever, however I do not see the flare over any players. Are you possibly insane, kalis?

alt Re: why error? a nil value

kalis
User Off Offline

Zitieren
this lua still making
in start not appear error but
Lua have hook "say"
when you create light with cmd "test"
And try to create 2,3 light ,go remove all light you created
It will error !
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht