So i’m working on a little game using onCollision event’s :
local function onCollision(event) if event.phase == "began" and gameIsActive == true then local obj1 = event.object1; local obj2 = event.object2; if obj1.name == "bill" then if obj2.name == "rocks" then gameover() elseif obj2.name == "" then end end end end Runtime:addEventListener( "collision", onCollision )
But i have a bit of a problem the code works as expected the first time it runs but is you restart the game i’m getting this error :
File: game.lua Line: 649 Attempt to call global 'gameover' (a table value) stack traceback: game.lua:649: in function \<game.lua:643\> ?: in function \<?:221\> 649 = if obj2.name == "rocks" then gameover() 643 = local function onCollision(event
)
Any idea what this could be?
gameover function :
function gameover() rightTAP:removeEventListener("tap", movePLAYERr) leftTAP:removeEventListener("tap", movePLAYERl) timer.pause(spawnBits) timer.pause(Rockspawner1) timer.pause(tmrscore) timer.pause(updateScoretimer) timer.pause(spawnDinosControll) audio.pause( drillingChannel ) drillbg.isVisible = false scoreText.isVisible = false Restartg = display.newText( "Restart", 0, 0,nil, 20) Restartg:setFillColor(0, 0, 0) screenGroup:insert(Restartg) Restartg.x= display.contentWidth/2 Restartg.y= display.contentHeight/2 + 160 Restartg:addEventListener("tap", RestartGame1) end