This is what I have :
local function onPlayerCollision( event ) if event.phase =="began" then composer.gotoScene("restart", options) end end function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("show started") player:addEventListener("onPlayerCollision") elseif ( phase == "did" ) then print("show showing objects") Runtime:addEventListener("touch", onTouch) end end function scene:hide(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("hide started") composer.removeScene( "start" ) player:removeEventListener("onPlayerCollision") elseif ( phase == "did" ) then print("hide removing objects") Runtime:removeEventListener("touch", onTouch) end end
And I’m constantly getting this error :
ERROR: Runtime error 11:49:33.912 addEventListener: listener cannot be nil: nil 11:49:33.912 stack traceback: 11:49:33.912 [C]: in function 'error' 11:49:33.912 ?: in function 'getOrCreateTable' 11:49:33.912 ?: in function 'addEventListener' 11:49:33.912 ?: in function 'addEventListener' 11:49:33.912 ?: in function 'addEventListener' 11:49:33.912 C:\Users\user\Documents\Corona Projects\app\game.lua:96: in function '?' 11:49:33.912 ?: in function 'dispatchEvent' 11:49:33.912 ?: in function '\_nextTransition' 11:49:33.912 ?: in function \<?:1492\> 11:49:33.912 (tail call): ? 11:49:33.912 ?: in function '?' 11:49:33.912 ?: in function \<?:182\> 11:49:35.521
This is line 96 :
player:addEventListener("onPlayerCollision")
I also tried :
player:addEventListener("onCollision")