pros/cons of where you setup local variable for scene? (main chunk variable vs parameter of scene)

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 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- \<== EXAMPLE HERE local function onSceneTouch( self, event ) . . .

B) parameter of the scene

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() scene.image = nil &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-- \<== EXAMPLE HERE local function onSceneTouch( self, event ) . . . &nbsp;

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:

http://developer.coronalabs.com/forum/2012/08/22/storyboard-scenes-and-modules

http://www.coronalabs.com/blog/2012/04/27/scene-overlays-and-parameter-passing/

Hi Greg,

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.

http://www.coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

Hope this helps!

Brent

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

But let me know if I’ve missed something…

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:

http://developer.coronalabs.com/forum/2012/08/22/storyboard-scenes-and-modules

http://www.coronalabs.com/blog/2012/04/27/scene-overlays-and-parameter-passing/

Hi Greg,

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.

http://www.coronalabs.com/blog/2013/08/20/tutorial-reloading-storyboard-scenes/

Hope this helps!

Brent

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

But let me know if I’ve missed something…