Storyboard global or not?

In the video tutorial that recently went out, there’s a demonstration of loading up the storyboard every time you change scenes. Why would you do this? Why not create a global storyboard reference and just reuse it every time?

I can’t really conceptualize that method, but other devs have implemented that. I guess for ease of code and tidiness, I always make new scenes as actual files, and load them that way. 

Here’s a tutorial with dev code showing how levels/scenes can be loaded with Storyboard:
 

http://www.newnams.com/corona-level-selection-tutorial/

Main.lua -

s = require(‘storyboard’)

s.gotoScene(‘myscene’)

Now all you need to do is have at the top of any scene file…

local scene = s.newScene()

Reloading the storyboard every time seems like a waste, although I don’t necessarily know what’s under the hood. Including sb in every scene is more bookkeeping and possibly memory thrashing?

You missed a very important part…  Things executed in the main chunk execute once.  Period… unless the scene is un-required using storyboard.removeScene().  So if you’re not doing removeScene() it’s not being reloaded… But wait, there’s more…

If I understand correctly once a module is required, even if it’s "require"ed in other modules, it’s still only loaded once.  Thus loading it local in main.lua is the only time storyboard actually loads with regards to the code.  You just need to make a local reference to it in modules.

The use of globals is a peril filled danger zone.  You can’t trust that some other module isn’t going to use a variable called “s” (in the example above) and use it as a global which would trash your entire storyboard object.

I can’t really conceptualize that method, but other devs have implemented that. I guess for ease of code and tidiness, I always make new scenes as actual files, and load them that way. 

Here’s a tutorial with dev code showing how levels/scenes can be loaded with Storyboard:
 

http://www.newnams.com/corona-level-selection-tutorial/

Main.lua -

s = require(‘storyboard’)

s.gotoScene(‘myscene’)

Now all you need to do is have at the top of any scene file…

local scene = s.newScene()

Reloading the storyboard every time seems like a waste, although I don’t necessarily know what’s under the hood. Including sb in every scene is more bookkeeping and possibly memory thrashing?

You missed a very important part…  Things executed in the main chunk execute once.  Period… unless the scene is un-required using storyboard.removeScene().  So if you’re not doing removeScene() it’s not being reloaded… But wait, there’s more…

If I understand correctly once a module is required, even if it’s "require"ed in other modules, it’s still only loaded once.  Thus loading it local in main.lua is the only time storyboard actually loads with regards to the code.  You just need to make a local reference to it in modules.

The use of globals is a peril filled danger zone.  You can’t trust that some other module isn’t going to use a variable called “s” (in the example above) and use it as a global which would trash your entire storyboard object.