Question about createScene

I have been using director for years and am finally switching over to storyboard, but the way the sample code was written was really impractical to replicate in my app (Defining all of the variables at the top and putting the code on createScene). Of course, there could very well be a good reason for doing that. So, I wanted to know if it was preferable to put the majority of scene creation outside of the createScene event like I am demonstrating below. I need the app to run smoothly, so I did not want to stray from the demo before asking. Any advice would be appreciated.


-------what I want to do


local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

– Most of my code here.

function scene:createScene( event )

 --Empty

end

function scene:enterScene( event )

  --Call  content update functions

end

function scene:destroyScene( event )

    --Remove listeners

end


-------how it is shown


local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

– Variable and function names

function scene:createScene( event )

 --Most of the code

end

function scene:enterScene( event )

  --Create content that may change

end

function scene:destroyScene( event )

    --Remove listeners

end

Without knowing too much about the project I would say it is fine to do it your way if you had to.  You can pretty much do anything the “storyboard” way, it may just take some rethinking.  Keep in mind what you probably should do is still add your display objects to the scene’s group in the createScene function:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- Most of my code here. function scene:createScene( event ) --group:insert(obj1) end function scene:enterScene( event ) --Call content update functions end function scene:destroyScene( event ) --Remove listeners end

Thank you for the response. It sounds like you are saying that I should be ok changing my code and that is good to hear.

I am just wondering if createScene is a little redundant because I am under the impression that it is called only when the module is loaded and therefor could be added without the call. The reason I want to do that is that adding all of my content into it causes it to be local to that function and then I cannot update without forward referencing outside of that function. That takes quite a bit of work to add and maintain on extremely large code files and it appears that it can all be easily sidestepped by not even calling that function at all. Of course, I assume that there is probably a really important reason that I am not seeing it done if it takes all of that extra work. Is this just a matter of preference that I am over-thinking or are there real benefits to the other practice?  I do not want to code in a less efficient manner for the sake of ease, but I do not want to spend time trying to tailor my app to fit inside of a more commonly preferred style.

Well I think what’s also important is that it helps take care of memory management for you. So if you do the work up front it can help relieve the headache later on. At first it seemed redundant and cumbersome to me too, but if you stick with the “proper” story board way then it becomes second nature later on.

Without knowing too much about the project I would say it is fine to do it your way if you had to.  You can pretty much do anything the “storyboard” way, it may just take some rethinking.  Keep in mind what you probably should do is still add your display objects to the scene’s group in the createScene function:

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() -- Most of my code here. function scene:createScene( event ) --group:insert(obj1) end function scene:enterScene( event ) --Call content update functions end function scene:destroyScene( event ) --Remove listeners end

Thank you for the response. It sounds like you are saying that I should be ok changing my code and that is good to hear.

I am just wondering if createScene is a little redundant because I am under the impression that it is called only when the module is loaded and therefor could be added without the call. The reason I want to do that is that adding all of my content into it causes it to be local to that function and then I cannot update without forward referencing outside of that function. That takes quite a bit of work to add and maintain on extremely large code files and it appears that it can all be easily sidestepped by not even calling that function at all. Of course, I assume that there is probably a really important reason that I am not seeing it done if it takes all of that extra work. Is this just a matter of preference that I am over-thinking or are there real benefits to the other practice?  I do not want to code in a less efficient manner for the sake of ease, but I do not want to spend time trying to tailor my app to fit inside of a more commonly preferred style.

Well I think what’s also important is that it helps take care of memory management for you. So if you do the work up front it can help relieve the headache later on. At first it seemed redundant and cumbersome to me too, but if you stick with the “proper” story board way then it becomes second nature later on.