Call onLocalCollision every second? How? (please help!)

okay, so I have a school project where I am showing a small game where all you is shoot a monster, but that don’t work; I get this error:

main.lua:118: attempt to index local ‘event’ (a nil value)

stack traceback:

                 main.lua:118: in function <main.lua:117>

                 ?: in function <?:169>

Do you want to relaunch the project?

Here’s the code that creates the error (it’s line 117 to 129):

local function onLocalCollision( self, event )

  if event.phase == “began” and self.name == “bullet” and event.other.name == “enemy” then

    display.remove( enemy )

  end

end

bullet.collision = onLocalCollision

bullet:addEventListener( “collision” )

enemy.collision = onLocalCollision

enemy:addEventListener( “collision” )

Runtime:addEventListener( “enterFrame”, onLocalCollision )

Thanks in advance!

That’s not going to work because your enterFrame event is going to fire the function independent of the bullet and enemy, and it doesn’t have a “self”.

Bullet fires a collision, it calls onLocalCollision(bullet, event)

Enemy fires a collision, it calls onLocalCollision(enemy, event)

Runtime fires an enterFrame, it calls onLocalCollision(event,nil)

The event is meant to be triggered when two objects collide. What is it you’re trying to do?

If you can post a larger snippet inside of code tags 

[lua]Some code here[/lua]

, we can probably help you get it running.

That’s not going to work because your enterFrame event is going to fire the function independent of the bullet and enemy, and it doesn’t have a “self”.

Bullet fires a collision, it calls onLocalCollision(bullet, event)

Enemy fires a collision, it calls onLocalCollision(enemy, event)

Runtime fires an enterFrame, it calls onLocalCollision(event,nil)

The event is meant to be triggered when two objects collide. What is it you’re trying to do?

If you can post a larger snippet inside of code tags 

[lua]Some code here[/lua]

, we can probably help you get it running.