What are the pro/cons of where to store variables you want across the life of a scene between the two approaches below. Do both ok from a memory management and variable scope type perspective? Is the recommendation to use option (a) ?
a) local variable in the main chunk
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local image, text1, text2, text3, memTimer -- \<== EXAMPLE HERE local function onSceneTouch( self, event ) . . .
B) parameter of the scene
local storyboard = require( "storyboard" ) local scene = storyboard.newScene() scene.image = nil -- \<== EXAMPLE HERE local function onSceneTouch( self, event ) . . .
From your question it appears you are looking for a Corona employee to weigh in, but FWIW you should stick with the first option. Unless you are taking the time to give each scene a unique name, the second option might be a bit more work than you want.
See these links for a bit more information about storyboard, modules and persistant variables though or within scenes:
Did you catch this week’s tutorial video on Storyboard? It focuses on how to reload scenes, but it also discusses a convenient way to handle (store) variables that you need to access from scene to scene.
thanks guys - had a look at the tutorial which was good - didn’t explicitly answer my question, but indicated using local variables in the main chunk seems to be best practice/ok. I thought I remembered reading some gotchas re memory optimization re using variables in the main chunk but I couldn’t find the reference now.
So overall it seems using variables in the main chunk of a storyboard file is:
* best practice
* doesn’t has any scoping gottchas (seems to be retained during the life of the scene)
* can’t think off hand of any advantages to putting the variable in the scene (e.g. scene.myvar = 123) instead
From your question it appears you are looking for a Corona employee to weigh in, but FWIW you should stick with the first option. Unless you are taking the time to give each scene a unique name, the second option might be a bit more work than you want.
See these links for a bit more information about storyboard, modules and persistant variables though or within scenes:
Did you catch this week’s tutorial video on Storyboard? It focuses on how to reload scenes, but it also discusses a convenient way to handle (store) variables that you need to access from scene to scene.
thanks guys - had a look at the tutorial which was good - didn’t explicitly answer my question, but indicated using local variables in the main chunk seems to be best practice/ok. I thought I remembered reading some gotchas re memory optimization re using variables in the main chunk but I couldn’t find the reference now.
So overall it seems using variables in the main chunk of a storyboard file is:
* best practice
* doesn’t has any scoping gottchas (seems to be retained during the life of the scene)
* can’t think off hand of any advantages to putting the variable in the scene (e.g. scene.myvar = 123) instead