Final Question

I have posted a few cries for help in the past few weeks and I thank you all for the help. Now I have one final question.

I have the following collision event(print( “Event” ) is just there because i would prefer not to give out the code online at this point):

 local onPlayerCollision = function( self, event )  
 if event.other.name == "Enemy Bullet" then  
 print( "Event" )  
 end  
 end  

and the object it is responding to:

 local playerSheet = sprite.newSpriteSheet("images/Walking/Walk.png", 27, 99.5)  
 local playerSet = sprite.newSpriteSet( playerSheet, 1, 8 )  
 sprite.add( playerSet, "player", 1, 8, 1000, 0 )  
 player = sprite.newSprite( playerSet )  
 player.x = display.contentWidth / 4  
 player.y = display.contentHeight / 3  
 player.name = "Player"  
 player.collision = onPlayerCollision  
 player:addEventListener( "collision", onPlayerCollision )  
 physics.addBody( player, {bounce=0.2, friction=0.5, filter=playerCollisionFilter} )  
 localGroup:insert(player)  

The problem is that when I run it in the simulator… i get the error that ‘event’ is a nil value… please help… [import]uid: 26946 topic_id: 13717 reply_id: 313717[/import]

try using this
[lua] local onPlayerCollision = function(event )
if event.other.name == “Enemy Bullet” then
print( “Event” )
end
end[/lua]
[lua] local playerSheet = sprite.newSpriteSheet(“images/Walking/Walk.png”, 27, 99.5)
local playerSet = sprite.newSpriteSet( playerSheet, 1, 8 )
sprite.add( playerSet, “player”, 1, 8, 1000, 0 )
player = sprite.newSprite( playerSet )
player.x = display.contentWidth / 4
player.y = display.contentHeight / 3
player.name = “Player”
player:addEventListener( “collision”, onPlayerCollision )
physics.addBody( player, {bounce=0.2, friction=0.5, filter=playerCollisionFilter} )
localGroup:insert(player)[/lua] [import]uid: 71210 topic_id: 13717 reply_id: 50378[/import]

Okay… that sort of works… but now I have a follow-up question

Why is it that in this function:

  
local onPlayerCollision = function( event )  
 if event.other.name == "Enemy Bullet" then  
 event.other:removeSelf()  
 timer.cancel( blah )  
 end  
end  
  

returns the error: “play.lua:147: ERROR: Attempt to remove an object that’s already been removed from the stage or whose parent/ancestor group has already been removed.”

I appologize for any inconvenience… [import]uid: 26946 topic_id: 13717 reply_id: 50523[/import]

what kind of physics body is “Enemy Bullet” ?
this error occurs when same object is tried to be removed more than 1 times. [import]uid: 71210 topic_id: 13717 reply_id: 50533[/import]

Just a regular physics body. This is the code if that helps…

physics.addBody( enemyBullets[eB], {bounce=0.1, friction=0.1, filter=enemyBulletCollisionFilter} )  
  

[import]uid: 26946 topic_id: 13717 reply_id: 50741[/import]

what is this timer blah ? is ti available for each “other” object ?
else there is a chance that you are trying to remove it more than once.
try using this
[lua]local onPlayerCollision = function( event )
if event.other.name == “Enemy Bullet” then
event.other:removeSelf()
if blah ~= nil then
timer.cancel( blah )
blah = nil
end
end
end[/lua] [import]uid: 71210 topic_id: 13717 reply_id: 50799[/import]

haha… the timer “blah” is the timer for the enemy to fire bullets at me… i was just really tired and didn’t feel like thinking so i just used blah… and thank you that worked…
[import]uid: 26946 topic_id: 13717 reply_id: 50811[/import]

yea… I too was laughing at the strange naming when I was reading the code I posted…Good to know that it worked. [import]uid: 71210 topic_id: 13717 reply_id: 50813[/import]

renvis@technowand is all over the place on posts. Everywhere I look he’s responding back and actually solving peoples problems.

Corona community is great.
ng
[import]uid: 61600 topic_id: 13717 reply_id: 50983[/import]