Cannot Call fucntions when i move back to a scene

---------------------------------------------------------------------------------- -- -- main.lua -- ---------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) storyboard.purgeOnSceneChange = true local scene = storyboard.newScene() local globalVariables = require "globalVariables" -- include Corona's "physics" library local physics --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -------------------------------------------- --Local Variables -------------------------- -------------------------------------------- local screenWidth = display.contentWidth local screenHeight = display.contentHeight local groupCreate local menuBackground local titleBlock local titleBreaker local titleSound = audio.loadSound("menu sounds/blockSound.mp3") local menuBall local ballHitSound = audio.loadSound("menu sounds/ball hit.mp3") local ballHit = 0 local playButton local statsButton local volumeKey local volumeMuteKey -------------------------------------------- --Local Variables Ended -------------------- -------------------------------------------- ------------------------------------------- -- Local Functions ------------------------ ------------------------------------------- function titleBlock() titleBlock = display.newImageRect("menu images/logo\_block.png", 150, 50) titleBlock.x, titleBlock.y = screenWidth/2, 100 transition.from( titleBlock, { time = 1500, alpha = 0, x = screenWidth+50, y = 100, transition = easing.outExpo} ) groupCreate:insert(titleBlock) end function titleBreaker() titleBreaker = display.newImageRect("menu images/logo\_breaker.png", 250, 50) titleBreaker.x, titleBreaker.y = screenWidth/2, 150 transition.from( titleBreaker, { time = 1500, alpha = 0, x = -50, y = 150 , transition = easing.outExpo} ) groupCreate:insert(titleBreaker) end function titleSoundPlay() audio.play(titleSound) end function ballCollision() if ballHit \<= 3 then audio.play(ballHitSound) end ballHit = ballHit + 1 end function drawMenuBall() menuBall = display.newImage("menu images/baseball ball.png") menuBall.x = screenWidth/2 menuBall.y = -10 menuBall:scale(0.25,0.25) physics.addBody(menuBall, {density = 1, friction = 0.3, bounce = 0.5, radius = 13}) menuBall.bodyType = 'dynamic' groupCreate:insert(menuBall) menuBall.preCollision = ballCollision menuBall:addEventListener("preCollision", ballCollision) end function changeScene() storyboard.gotoScene("level.level 1.level1") end function onPlayCollision(event) if event.phase == "began" then if globalVariables.gameSound == "On" then audio.play(ballHitSound) end timer.performWithDelay(50, changeScene,1) end end function onPlayClick(event) menuBall:applyForce( -100, -200, menuBall.x, menuBall.y ) end function playGameButton() playButton = display.newImage("menu images/play button.png") playButton:scale(0.5,0.5) playButton.x, playButton.y = (screenWidth/2) - 70, (screenHeight/2) + 60 playButtonShape = {-40,-15, 40,-15, 40,15, -40,15} physics.addBody(playButton, {shape = playButtonShape}) playButton.bodyType = "static" transition.from( playButton, { time = 1500, alpha = 0, x = -50, y = (screenHeight/2) + 60, transition = easing.outExpo} ) groupCreate:insert(playButton) playButton:addEventListener("touch", onPlayClick) playButton:addEventListener("collision", onPlayCollision) end function muteKey() volumeMuteKey = display.newImage("menu images/cross.png") volumeMuteKey.alpha = 0 volumeMuteKey:setReferencePoint(display.TopLeftReferencePoint) volumeMuteKey:scale(0.3,0.3) volumeMuteKey.x, volumeMuteKey.y = 35 , screenHeight - 35 groupCreate:insert(volumeMuteKey) end function onVolumeKeyTouch(event) if event.phase == "began" then if volumeMuteKey.alpha == 0 and globalVariables.gameSound == "On" then volumeMuteKey.alpha = 1 globalVariables.gameSound = "Off" else volumeMuteKey.alpha = 0 globalVariables.gameSound = "On" end end end function volumeButton() volumeKey = display.newImage("menu images/music.png") volumeKey:setReferencePoint(display.TopLeftReferencePoint) volumeKey:scale(0.6,0.6) volumeKey.x, volumeKey.y = 8 , screenHeight - 60 transition.from( volumeKey, { time = 1500, alpha = 0, x = -50, y = screenHeight - 60, transition = easing.outExpo} ) groupCreate:insert(volumeKey) muteKey() volumeKey:addEventListener("touch", onVolumeKeyTouch) end ------------------------------------------- -- Local Functions Eneded ----------------- ------------------------------------------- -- Called when the scene's view does not exist: function scene:createScene( event ) groupCreate = self.view physics = require "physics" physics.start() physics.setGravity(0,8) --physics.setDrawMode("hybrid") menuBackground = display.newImageRect( "menu images/menu background.jpg", display.contentWidth, display.contentHeight ) menuBackground.x, menuBackground.y = screenWidth/2, -screenHeight/2 menuBackgroundShape = {-screenWidth/2,(screenHeight/2)-0.1, screenWidth/2,(screenHeight/2)-0.1, screenWidth/2,screenHeight/2, -screenWidth/2,screenHeight/2} physics.addBody(menuBackground, {density = 1, friction = 0.3, bounce = 0.5, shape = menuBackgroundShape}) menuBackground.bodyType = "dynamic" groupCreate:insert(menuBackground) ground = display.newRect(0, screenHeight, screenWidth, 0) physics.addBody(ground, "static", {density=3.0, friction=0.5, bounce=0.3}) groupCreate:insert(menuBackground) timer.performWithDelay(3000, titleBlock, 1) timer.performWithDelay(3000, titleBreaker, 1) timer.performWithDelay(3000, titleSoundPlay, 1) timer.performWithDelay(4000, drawMenuBall, 1) timer.performWithDelay(8000, playGameButton, 1) timer.performWithDelay(8000, volumeButton, 1) end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view menuBall:removeEventListener("preCollision", ballCollision) playButton:removeEventListener("collision", onPlayCollision) volumeKey:removeEventListener("touch", onVolumeKeyTouch) storyboard.removeAll() end -- Called prior to the removal of scene's "view" (display group) function scene:destroyScene( event ) local group = self.view package.loaded[physics] = nil physics = nil end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene

When i execute the above code it works fine for first time but when i come back to my menu scene(above code) these functions do not execute :-

timer.performWithDelay(3000, titleBlock, 1)

timer.performWithDelay(3000, titleBreaker, 1)

Typically your main.lua should not be a scene (I know it’s technically possible, but there are very few reasons to go to the work to make it happen).  It should be a file that initializes everything and jumps to your first real scene (typically menu.lua, splash.lua or some other starter screen).  In that case main.lua should contain:

local storyboard = require("storyboard") storyboard.purgeOnSceneChange = true -- -- any other system side initialization -- -- last lines of main.lua: local options = { &nbsp;&nbsp;&nbsp;&nbsp; effect = "fade", -- or whatever effect you want &nbsp;&nbsp;&nbsp;&nbsp; time = 500 } storyboard.gotoScene("menu", options)

Then each of your scene files, like menu.lua would have:

local storyboard = require("storyboard") local scene = storyboard.newScene() &nbsp; function scene:createScene(event) &nbsp; -- your create code end &nbsp; function scene:enterScene(event) &nbsp; -- your scene start up&nbsp; code end &nbsp; function scene:exitScene(event) &nbsp; -- your scene stop code end &nbsp; function scene:destoryScene(event) &nbsp; -- your code to clean up any thing created in create scene that isn't cleaned up for you like display items inserted into "group" end &nbsp; &nbsp; -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene

And you can’t do a storyboard.gotoScene(“main”) because it’s not a scene.  You would go back to “menu” or wherever is logical.

Generally you will want to start your timers in enterScene, not createScene.

Typically your main.lua should not be a scene (I know it’s technically possible, but there are very few reasons to go to the work to make it happen).  It should be a file that initializes everything and jumps to your first real scene (typically menu.lua, splash.lua or some other starter screen).  In that case main.lua should contain:

local storyboard = require("storyboard") storyboard.purgeOnSceneChange = true -- -- any other system side initialization -- -- last lines of main.lua: local options = { &nbsp;&nbsp;&nbsp;&nbsp; effect = "fade", -- or whatever effect you want &nbsp;&nbsp;&nbsp;&nbsp; time = 500 } storyboard.gotoScene("menu", options)

Then each of your scene files, like menu.lua would have:

local storyboard = require("storyboard") local scene = storyboard.newScene() &nbsp; function scene:createScene(event) &nbsp; -- your create code end &nbsp; function scene:enterScene(event) &nbsp; -- your scene start up&nbsp; code end &nbsp; function scene:exitScene(event) &nbsp; -- your scene stop code end &nbsp; function scene:destoryScene(event) &nbsp; -- your code to clean up any thing created in create scene that isn't cleaned up for you like display items inserted into "group" end &nbsp; &nbsp; -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene

And you can’t do a storyboard.gotoScene(“main”) because it’s not a scene.  You would go back to “menu” or wherever is logical.

Generally you will want to start your timers in enterScene, not createScene.