When i am in the scene of Level_1 and then i choose to exit the level and the restarting again the level_1 i got this error when i press the exit button, but i dont know why ?
This is the function in Menu that calls the level_1 when i press play
function onObjectTap( event ) if(event.target.name == "play\_but") then print( "play" ) composer.removeScene( "level\_1" ) local LAST\_LEVEL\_TO\_DESTROY = "level\_1" local options = { effect = "crossFade", time = 500 } composer.gotoScene( LAST\_LEVEL\_TO\_DESTROY , options) elseif(event.target.name == "levels")then hideSelf() levels\_class.showLevels() end return true end
AND this is my lua file for pause_controls
local pause\_controls = {} local widget = require("widget") local PATH = "Pause\_icon/" local group = display.newGroup() local PLAY\_STATE = "PLAY STATE" local PAUSE\_STATE = "PAUSE STATE" local STATE = PLAY\_STATE local SCROLL\_HEIGH = display.actualContentHeight\*0.3 local SCROLL\_WIDTH = display.actualContentWidth\*0.5 local exit = display.newImage( PATH.."exit.png") local pause = display.newImage( PATH.."pause.png") local play = display.newImage( PATH.."play.png") local restart = display.newImage( PATH.."restart.png") local composer local LEVEL\_NAME local camera local play\_eve local exit\_restart local background = display.newImage( PATH.."menu\_pause\_background.png") background.anchorX = 0 background.anchorY = 0 function pause\_controls:setGroupAndComposer(\_levelName, GROUP , \_composer, \_camera) composer = \_composer GROUP:insert( group ) LEVEL\_NAME = \_levelName camera = \_camera end local scrollView = widget.newScrollView { friction = 0, height = SCROLL\_HEIGH, width = SCROLL\_WIDTH, bottomPadding = 0, id = "onBottom", horizontalScrollDisabled = false, verticalScrollDisabled = false, isLocked = true, hideBackground = true } scrollView.anchorX = 2 scrollView.anchorY = 0 scrollView.x = display.actualContentWidth scrollView.y = 0 scrollView.width = 0 background.height = SCROLL\_HEIGH background.width = SCROLL\_WIDTH exit.y = SCROLL\_HEIGH/2 restart.y = SCROLL\_HEIGH/2 play.y = SCROLL\_HEIGH/2 pause.y = SCROLL\_HEIGH/2 scrollView:insert( background ) scrollView:insert( exit ) scrollView:insert( restart ) group:insert( play ) group:insert( pause ) group:insert( scrollView ) scrollView:toBack() exit.x = SCROLL\_WIDTH \* (1/3) - exit.contentWidth/2 restart.x = SCROLL\_WIDTH \*(2/3) - restart.contentWidth/2 play.x = display.actualContentWidth - play.contentWidth/2 pause.x = play.x play.alpha = 0 local TIME = 300 local play\_eve local function RemoveScene() -- composer.removeScene( LEVEL\_NAME ) end function exit\_restart(event) if(event.target == exit) then print("exit") camera:destroy() composer.gotoScene( "MenuScene" ) timer.performWithDelay( 10, RemoveScene ) elseif(event.target == restart) then print(LEVEL\_NAME) composer.gotoScene( LEVEL\_NAME) end end local function end\_anim(event) play:addEventListener( "tap", play\_eve ) if(STATE == PAUSE\_STATE)then exit:addEventListener( "tap", exit\_restart ) restart:addEventListener( "tap", exit\_restart ) end end function play\_eve(event) play:removeEventListener( "tap", play\_eve ) exit:removeEventListener( "tap", exit\_restart ) restart:removeEventListener( "tap", exit\_restart ) if (STATE == PLAY\_STATE) then STATE = PAUSE\_STATE transition.to( scrollView, {width = SCROLL\_WIDTH , time = TIME , onComplete = end\_anim} ) transition.to(pause , {rotation = 360 , time = TIME , alpha = 0}) transition.to(play , {rotation = 360 , time = TIME , alpha = 1}) elseif (STATE == PAUSE\_STATE)then STATE = PLAY\_STATE transition.to( scrollView, {width = 0 , time = TIME , onComplete = end\_anim} ) transition.to(pause , {rotation = 360 , time = TIME , alpha = 1}) transition.to(play , {rotation = 360 , time = TIME , alpha = 0}) end return true end play:addEventListener( "tap", play\_eve ) play.isHitTestable = true return pause\_controls
the error in then line 115 that i got in this file is this
exit:removeEventListener( "tap", exit\_restart )
and my level_1 file
--BASE GAME LEVELS local composer = require( "composer" ) local scene = composer.newScene() local Controls sceneType = "level" --/////////////////////////////////// CAMERA AND STAGE///////////////////////////////////////// function scene:create( event ) local sceneGroup = self.view --STAGE local background = display.newRect( display.contentWidth/2, display.contentHeight/2, display.contentWidth ,display.contentHeight) sceneGroup:insert( background ) local perspective = require("perspective") local camera = perspective.createView(3) camera:setBounds(display.contentCenterX, 500, display.contentCenterY, 500) --sceneGroup:insert( camera ) --//////////////////////////////////// PHYSICS ///////////////////////////////////////////////// local physics = require( "physics" ) physics.start() --//////////////////////////////// PLAYER AND ACCESORIES/////////////////////////////////////// local player = require("player") player.IniPlayerVars(physics, sceneGroup) camera:add(player.square, 1, false) camera:setFocus(player.square) camera:track() --BEAM local Ball = require( "electric\_ball" )-----MAX FORCE Ball.IniBallVars(camera, physics , player , player.square.mass\*5 , sceneGroup) --//////////////////////////////////// PLANETS ///////////////////////////////////////////////// local planets = require("planet") planets.InitVars(physics , camera , sceneGroup) --//////////////////////////////////// CONTROLS /////////////////////////////////////////////// Controls = require("controls") Controls.Init(background , player , Ball, sceneGroup) local Pause\_controls = require("pause\_controls") local CURREN\_SCENE = composer.getSceneName( "current" ) Pause\_controls:setGroupAndComposer(CURREN\_SCENE, sceneGroup , composer , camera) -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. end --------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) --------------------------------------------------------------------------------- return scene