Destroy game scene when changing to lose scene.(composer)

Hey guys I can’t figure out how to make it so when my game switches to the lose scene and when you go back into the game it starts the game over. Here is the game.lua code

--game.lua local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- -- local forward references should go here -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local sceneGroup = self.view local actualWidth = display.actualContentWidth local actualHeight = display.actualContentHeight local actualWidth1 = display.actualContentWidth/2 local actualHeight1 = display.actualContentHeight/2 local centerX = display.contentCenterX local centerY = display.contentCenterY local jelly = nil local BG = display.newImage("BG.png",centerX,centerY,actualWidth,actualHeight) sceneGroup:insert(BG) local score = 0 local scoredisplay = display.newText(score,0,0,"comic.ttf",30) scoredisplay.x = centerX + actualWidth1-20 scoredisplay.y = centerY + actualHeight1-display.actualContentHeight+30 sceneGroup:insert(scoredisplay) jellys = {} local jellytable = {"Jelly (1).png","Jelly (2).png","Jelly (3).png","Jelly (4).png","Jelly (5).png"} local function spawnjelly( event ) local jelly = display.newImage(jellytable[math.random(5)],math.random(0,actualWidth1),math.random(0,actualHeight1)) jelly:scale(0.4,0.4) print("spawning jelly!") sceneGroup:insert(jelly) local function remove(event) jelly:removeSelf() jelly = nil score = score + 1 scoredisplay.text = score + 1 end jelly:addEventListener("tap",remove) end timer.performWithDelay( math.random(500,2000), spawnjelly,0 ) local function spawnbadjelly(event) local badjelly = display.newImage("jelly (6).png",math.random(0,actualWidth1),math.random(0,actualHeight1)) badjelly:scale(0.4,0.4) sceneGroup:insert(badjelly) local function lose(event) print("You lose") composer.gotoScene("lose") end badjelly:addEventListener("tap",lose) end timer.performWithDelay( math.random(500,2000), spawnbadjelly,0 ) end -- "scene:show()" function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

What do you mean start over? In your destroy scene put 

composer.removeScene("game")

–SonicX278

In your lose scene, just before  you go back to your game scene, do:

composer.removeScene("game") composer.gotoScene("game")

You cannot remove the scene from it’s own scene:destroy() function. scene:destroy() is only called after composer.removeScene() gets called somewhere else.

Rob

What do you mean start over? In your destroy scene put 

composer.removeScene("game")

–SonicX278

In your lose scene, just before  you go back to your game scene, do:

composer.removeScene("game") composer.gotoScene("game")

You cannot remove the scene from it’s own scene:destroy() function. scene:destroy() is only called after composer.removeScene() gets called somewhere else.

Rob