Killing Enemys

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Dr.FR0ST
Prole
Posts: 2
Joined: Thu Apr 17, 2014 2:32 pm

Killing Enemys

Post 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
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Killing Enemys

Post 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
Dr.FR0ST
Prole
Posts: 2
Joined: Thu Apr 17, 2014 2:32 pm

Re: Killing Enemys

Post by Dr.FR0ST »

Damn im so blind :D Thank you! My problem is solved :D
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests