local vars in destroyScene

just tidying up my code before I submit it, but just wondering something

I declare all my locals in the scene:createScene( event ) section of my script,  so

local loadingTimer loadingTimer = timer.performWithDelay( 800, runFunction, 1 )

then in my scene:destroyScene( event ) section of my script I remove the timer when I leave the scene with

if loadingTimer then timer.cancel( loadingTimer ); end loadingTimer = nil

but I’m just wondering, do I need to declare it as a local again??

does the local var bleed through the different parts of 1 storyboard scene, or seeing I declare the var as local in the createScene part it is only local there, and is global in the destoryscene part?

Generally you should pre-declare your locals just above createScene (outside of any function).   Then you just call them by their names without local (to either create them or remove them).  

with some of my locals I have to call them within the createScene. with these ones do I need to redeclare them in the destoryScene??

No.  Which locals are you creating in createScene?  Are they display objects?  If so, those should just be added to the scene’s group (and you don’t need to worry about removing them).  Otherwise, other objects should be forward declared before createScene.  Here is an example:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- local forward references should go here -- local loadingTimer -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- CREATE display objects and add them to 'group' here. -- Example use-case: Restore 'group' from previously saved state. local mySpecialFunction() loadingTimer = timer.performWithDelay( 800, runFunction, 1 ) end end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- INSERT code here (e.g. start timers, load audio, start listeners, etc.) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) end -- Called prior to the removal of scene's "view" (display group) function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, widgets, save state, etc.) if loadingTimer then timer.cancel( loadingTimer ); end loadingTimer = nil end

Generally you should pre-declare your locals just above createScene (outside of any function).   Then you just call them by their names without local (to either create them or remove them).  

with some of my locals I have to call them within the createScene. with these ones do I need to redeclare them in the destoryScene??

No.  Which locals are you creating in createScene?  Are they display objects?  If so, those should just be added to the scene’s group (and you don’t need to worry about removing them).  Otherwise, other objects should be forward declared before createScene.  Here is an example:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- local forward references should go here -- local loadingTimer -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view -- CREATE display objects and add them to 'group' here. -- Example use-case: Restore 'group' from previously saved state. local mySpecialFunction() loadingTimer = timer.performWithDelay( 800, runFunction, 1 ) end end -- Called immediately after scene has moved onscreen: function scene:enterScene( event ) local group = self.view -- INSERT code here (e.g. start timers, load audio, start listeners, etc.) end -- Called when scene is about to move offscreen: function scene:exitScene( event ) local group = self.view -- INSERT code here (e.g. stop timers, remove listeners, unload sounds, etc.) end -- Called prior to the removal of scene's "view" (display group) function scene:destroyScene( event ) local group = self.view -- INSERT code here (e.g. remove listeners, widgets, save state, etc.) if loadingTimer then timer.cancel( loadingTimer ); end loadingTimer = nil end