EventListener causing another EventListener to STOP working

Hey Guys,

Anyone know why or how the below code is causing another Ojbects eventListener to stop working

[lua]

placeFireLamp = function (event)
   if event.phase == “began” then
   print( “Placing FireLamp” )
   print( event.phase )

   powerup_fireLampObj[powerup_fireLampCount] = display.newSprite( sheetFireLamp, sequenceData)
   powerup_fireLampObj[powerup_fireLampCount].x = event.x
   powerup_fireLampObj[powerup_fireLampCount].y = event.y
   powerup_fireLampObj[powerup_fireLampCount]:play( )
   powerup_fireLampCount = powerup_fireLampCount + 1

   if powerup_fireLampCount >= 3 then
        print( “Cannot Place any more firelamps” )
        Runtime:removeEventListener(“touch”, placeFireLamp)
        timeKeep:resume()
        transition.resume(“bugTransitions”)
        timer.resume( tmr_createBug )
   end
end
end

Runtime:addEventListener(“touch”, placeFireLamp)
end

[/lua]

causes the following eventListener to stop working (e.g stops the Bugs from being tapped and killed)

[lua] --setup tab listener
bug[TotalBugs]:addEventListener( “tap”, bugKilled )[/lua]

You need to add:

return true

To the end of your function you posted there at the very least, as you are currenly letting the event bubble down to objects below and are basically saying “this event hasn’t been handled yet” by not returning true.

This tutorial should also help: http://coronalabs.com/blog/2013/10/01/tutorial-taptouch-anatomy/

Hey Thanks for the advise but still having the same issue, will keep the above in mind for the future though.

Here is my code now 

[lua] placeFireLamp = function (event)
if event.phase == “began” then
print( “Placing FireLamp” )
print( event.phase )

powerup_fireLampObj[powerup_fireLampCount] = display.newSprite( sheetFireLamp, sequenceData)
powerup_fireLampObj[powerup_fireLampCount].x = event.x
powerup_fireLampObj[powerup_fireLampCount].y = event.y
powerup_fireLampObj[powerup_fireLampCount]:play( )
powerup_fireLampCount = powerup_fireLampCount + 1

if powerup_fireLampCount >= 3 then
print( “Cannot Place any more firelamps” )
Runtime:removeEventListener(“touch”, placeFireLamp)
timeKeep:resume()
transition.resume(“bugTransitions”)
timer.resume( tmr_createBug )
end
end

return true
end

Runtime:addEventListener(“touch”, placeFireLamp)[/lua]

and here a video of the issue from my Dropbox account - https://www.dropbox.com/s/ixhpo6yjgy6vylr/EventListenerBug.mov

Just out of curiosity, if you change the bug event listener type to touch instead of tap, does it work then?

No sorry; same result, still appears to stop the listener for the bugs.

if I comment out [lua]Runtime:removeEventListener(“touch”, placeFireLamp)[/lua] It will just constantly create FireLamps hence why I need to remove it. 

I can probably code around it with a while loop but then I’ll be left with the touch events going off throughout the game causing more overhead.

Hey Guys,

Sorry to bug you but after days of trying to figure this out I’m still nowhere near figuring out what could be causing it.

Any more assistance would be fantastic.

At the moment this has halted development on my game as most other aspects beside the in-game store have been completed.

Again Thanks Guys

Danny

Sorry to hear that. 

If you make a runnable example for us, just using rectangles instead of sprites we might be able to fix this quickly. 

[member=‘Jonjonsson’] that may take some time due to the amount of images in total in the game. Could the GameScene.lua do or ?

I mean, start with a blank main.lua. When you click you place a rectangle, then another rect flies over and you print something out in console when you hit it instead of placing a rect.

Skip all scene stuff and unrelated logic. If the problem is still there it will be easy to spot. That is a pretty good way to try to fix issues that one has been battling for too long.

You can also try pasting the GameScene instead, but it can be hard to spot.

OMG [member=‘jonjonsson’] THANKYOU!!! … So I did what you said and I found the problem … here is the funny part. So In my BugSplatter “Tap” function I have a if statement that causes the bug “Tap” function not to fire if gameIsPaused = true

And in the above FireLamp event I was never turning this back to false so after the 3 lamps where placed and the game resumed because the game was still technically “paused” it wasn’t firing my “Tap” function

Thanks if I didn’t do the above I would probably not have picked up on that.

Cant believe it was this simple and I haven’t picked up on it haha feel kinda stupid now.

Great! :slight_smile:

You need to add:

return true

To the end of your function you posted there at the very least, as you are currenly letting the event bubble down to objects below and are basically saying “this event hasn’t been handled yet” by not returning true.

This tutorial should also help: http://coronalabs.com/blog/2013/10/01/tutorial-taptouch-anatomy/

Hey Thanks for the advise but still having the same issue, will keep the above in mind for the future though.

Here is my code now 

[lua] placeFireLamp = function (event)
if event.phase == “began” then
print( “Placing FireLamp” )
print( event.phase )

powerup_fireLampObj[powerup_fireLampCount] = display.newSprite( sheetFireLamp, sequenceData)
powerup_fireLampObj[powerup_fireLampCount].x = event.x
powerup_fireLampObj[powerup_fireLampCount].y = event.y
powerup_fireLampObj[powerup_fireLampCount]:play( )
powerup_fireLampCount = powerup_fireLampCount + 1

if powerup_fireLampCount >= 3 then
print( “Cannot Place any more firelamps” )
Runtime:removeEventListener(“touch”, placeFireLamp)
timeKeep:resume()
transition.resume(“bugTransitions”)
timer.resume( tmr_createBug )
end
end

return true
end

Runtime:addEventListener(“touch”, placeFireLamp)[/lua]

and here a video of the issue from my Dropbox account - https://www.dropbox.com/s/ixhpo6yjgy6vylr/EventListenerBug.mov

Just out of curiosity, if you change the bug event listener type to touch instead of tap, does it work then?

No sorry; same result, still appears to stop the listener for the bugs.

if I comment out [lua]Runtime:removeEventListener(“touch”, placeFireLamp)[/lua] It will just constantly create FireLamps hence why I need to remove it. 

I can probably code around it with a while loop but then I’ll be left with the touch events going off throughout the game causing more overhead.

Hey Guys,

Sorry to bug you but after days of trying to figure this out I’m still nowhere near figuring out what could be causing it.

Any more assistance would be fantastic.

At the moment this has halted development on my game as most other aspects beside the in-game store have been completed.

Again Thanks Guys

Danny

Sorry to hear that. 

If you make a runnable example for us, just using rectangles instead of sprites we might be able to fix this quickly. 

[member=‘Jonjonsson’] that may take some time due to the amount of images in total in the game. Could the GameScene.lua do or ?

I mean, start with a blank main.lua. When you click you place a rectangle, then another rect flies over and you print something out in console when you hit it instead of placing a rect.

Skip all scene stuff and unrelated logic. If the problem is still there it will be easy to spot. That is a pretty good way to try to fix issues that one has been battling for too long.

You can also try pasting the GameScene instead, but it can be hard to spot.

OMG [member=‘jonjonsson’] THANKYOU!!! … So I did what you said and I found the problem … here is the funny part. So In my BugSplatter “Tap” function I have a if statement that causes the bug “Tap” function not to fire if gameIsPaused = true

And in the above FireLamp event I was never turning this back to false so after the 3 lamps where placed and the game resumed because the game was still technically “paused” it wasn’t firing my “Tap” function

Thanks if I didn’t do the above I would probably not have picked up on that.

Cant believe it was this simple and I haven’t picked up on it haha feel kinda stupid now.