Page 1 of 1

Killing Enemys

Posted: Thu Apr 17, 2014 2:40 pm
by Dr.FR0ST
Hi! I want to kill an enemy with bullet but every time i shoot i get an error. Thats my code:

Code: Select all

function Enemy:update(dt)
	local i, o, w, s
	for i, o in ipairs(Enemy) do
		for w, s in ipairs(bullets) do
			if (s.x > w.x and s.x < w.x + w.width) and (s.y > w.y and s.y < w.y + w.height) then
				table.remove(bullets, w)
				table.remove(Enemy, i)
			end
		end
	end   
end
Error:
Image

Re: Killing Enemys

Posted: Thu Apr 17, 2014 3:15 pm
by veethree
You don't need this line:

Code: Select all

local i, o, w, s
I think your problem is in this line:

Code: Select all

if (s.x > w.x and s.x < w.x + w.width) and (s.y > w.y and s.y < w.y + w.height) then
w in this case is a number value not a table, I think you meant to put the o from the other loop there.

Code: Select all

if (s.x > o.x and s.x < o.x + o.width) and (s.y > o.y and s.y < o.y + woheight) then

Re: Killing Enemys

Posted: Thu Apr 17, 2014 5:05 pm
by Dr.FR0ST
Damn im so blind :D Thank you! My problem is solved :D