When i leave the game.lua scene to gameover.lua i get a Attempt to compare nil with number error
witch i understand because function explode deletes the ‘Jet’ but the Runtime:removeEventListener should prevent the error from coming up but its not, is there any fix for this?
ERROR:
Attempt to compare nil with number stack traceback: [C]: ? /Users/macuser/Desktop/spawn test/game.lua:299: in function \</Users/macuser/Desktop/spawn test/game.lua:297\> ?: in function \<?:218\>
MAIN.LUA:
display.setStatusBar( display.HiddenStatusBar ) local storyboard = require "storyboard" storyboard.purgeOnSceneChange = true storyboard.gotoScene( "start" )
GAME.LUA:
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() \_W = display.contentWidth \_H = display.contentHeight local physics = require("physics") physics.start() system.setAccelerometerInterval( 50 ); -- Set Accelerometer Interval function scene:enterScene( event ) local group = self.view print("game screen") -- START Function used to keep the player on screen local function wrap (event) ------- if jet.x \< -40 then jet.x = 415 end ---- if jet.x \> 415 then jet.x = -40 end ------- end -- END Function used to keep the player on screen Runtime:addEventListener("enterFrame", wrap) local function moveJet (event) -- Move to new Position jet.x = motionx + jet.x; jet.y = jet.y - motiony; -- Set New Angle jet.rotation = rotation; -- box if(jet.y\<0)then jet.y = 0; end if(jet.y\>510)then jet.y = 510; end -- end box end Runtime:addEventListener("enterFrame", moveJet) function explode() explosion.x = jet.x explosion.y = jet.y explosion.isVisible = true explosion:play() jet.isVisible = false timer.performWithDelay(1000, gameOver, 1) audio.play(explosionSound) audio.stop( helicopterSoundMusicChannel ) audio.setVolume( 0.15, { channel=explosionSound } ) -- set the volume on explosionSound end end function scene:exitScene( event ) local group = self.view Runtime:removeEventListener("enterFrame", moveJet) Runtime:removeEventListener("enterFrame", wrap) end