Hi Daniel,
The removing of local on your function has now made that a Global and can be seen throughout the project.
As you have found, if you dont remove the scene ‘things’ hang about unexpectedly…
If you want to keep variable and functions local to say sceneA (so only sceneA knows about that particular name) then in sceneA some where at the top of the coding just write ‘local onOrientation’ and then it should still work.
This subject can, my view, be a subject that is like holding down a sack of snakes… (ie Globals vs Locals vs modules- do a google search and you will see numerous debates on what is right/wrong)
To start you off here are a couple of links (but a big subject to one’s head around fully…)
http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/
http://www.ludicroussoftware.com/blog/2012/01/16/scope-in-corona/
http://lua-users.org/wiki/LuaDirectory --look for scoping
— Removing scenes
There is a more generalised way of doing this, in case you don’t know the sequence of scenes the user might select.
I have a module that I put all my formatting in and require that in each of my scenes (my formatted scenes are similar) and call that on createScene…
–================================
function scene:createScene( event )
local group = self.view
local Priorscene=storyboard.getPrevious ( )
if Priorscene~= nil then
storyboard.removeScene(Priorscene)
end
FormatSceneDisplay(group)
-=====
SceneDisplayObjects.SceneStatus=“SceneA creating”-- my internal footprinting to keep an eye on what is happening
print(SceneDisplayObjects.SceneStatus)
end
–===============================================
[Note: for debugging I push the following to a global in each function with the function name
[Sorry not a global- a module variable expose internally- separate subject]
SceneDisplayObjects.SceneStatus=“SceneA creating”
SceneDisplayObjects.SceneStatus=“SceneA WillEnter”
SceneDisplayObjects.SceneStatus=“SceneA Entered”
SceneDisplayObjects.SceneStatus=“SceneA Ending” and so-on…
You will see that at times things go ‘out of expected sequence’ such as when one scene starts another might not end until after the scene you started . Just helps understand Corona a bit …
—========memory monitoring etc
In my Globals module that I require in main.lua before starting story boards scenes I have this routine
----================MEMORY MONITOR=========
local function memUsage()
collectgarbage(“collect”)
_G.device.MemoryUsed = Utilities.roundToDecPlaces(collectgarbage( “count” ) ,2)-- alternate is maths.round(collectgarbage( “count” )
_G.device.textureMemoryUsed=system.getInfo(“textureMemoryUsed”)
if oldmemoryCount~= _G.device.MemoryUsed then
print( “Memory used”, _G.device.MemoryUsed, " TEXTURE Used",_G.device.textureMemoryUsed/1048576)
end
oldmemoryCount=_G.device.MemoryUsed
timer.performWithDelay( 4000, memUsage, 0 )
return _G
Good luck.
Alec