question on storyboard.newScene( "scene")

Hi all,
I am taking baby steps on trying out the storyboard api.
I can get it to work fine using the suggested approach of having separate modules for each of my scenes but when I try to use it all in the same module by passing a string scene name to the newScene function
I find that createScene event handler is never called for my first call to storyboard as in main.lua:

local storyboard = require( “storyboard” )
local scene = storyboard.newScene(“scene”)

storyboard.gotoScene( “scene”, “fade”, 400 )

The enterScene event handler is called but not the createScene handler.

Anything obvious I am doing wrong here?
Thanks,
-Dennis [import]uid: 108253 topic_id: 19806 reply_id: 319806[/import]

You have to have to have it in separate modules… gotoScene(“scenename”) loads a file called “scenename.lua”. That individual file has its own independent createScene, enterScene, etc.

[import]uid: 19626 topic_id: 19806 reply_id: 76824[/import]

Thanks for your reply but the docs indicate I can put all the stuff into one module, in my case main.lua by putting a scene name in the newScene call.
And it does work as I indicated except for the strange behavior I noted above.
I can get “around” the behavior by putting my initialization for the scene in enterScreen but the docs indicate createScene should be called by storyboard.
And I do notice that subsequent storyboard transitions to that scene do indeed call createScene. It’s just the very first time I call that scene that createScene does not get entered. [import]uid: 108253 topic_id: 19806 reply_id: 76887[/import]

Hmm… still no response on this.
Could someone from Ansca verify that when you put all the scene “modules” into main.lua and use the named scene method that createScene is indeed called the first time on the initial scene?
It certainly works when using separate modules but I can’t seem to get it to occur the very first time I call the initial scene.
Subsequent “calls” to the initial scene do seem to work.
Thanks,
-Dennis

P.S. If it indeed works as advertised then what could be causing my app behavior?
[import]uid: 108253 topic_id: 19806 reply_id: 77346[/import]

Can you point me to the docs that says you have have multiple scenes in one lua file? Everything I’ve scene says each scene needs to be its own lua file.

[import]uid: 19626 topic_id: 19806 reply_id: 77352[/import]

Hi Rob,
The link is:
http://developer.anscamobile.com/reference/index/storyboardnewscene
There is an optional parameter to newScene called sceneName.
In my case I have 2 newScene calls in main.lua
scene = storyboard.newScene( “scene” )
scene1 = storyboard.newScene( “scene1” )
The actual eventhandlers are just taken from the storyboard template.
-Dennis

P.S. Also in the storyboard discussion topic they mention they added the optional scene name.
http://developer.anscamobile.com/forum/2011/11/16/storyboard-api-questions
About 1/2 way down in a post from jonathanbeebe (Ansca Staff) [import]uid: 108253 topic_id: 19806 reply_id: 77382[/import]

so do you have a scene1:createScene() function in addition to the scene:createScene() function? [import]uid: 19626 topic_id: 19806 reply_id: 77395[/import]

Yes here is the heavily edited version of my code in main.lua (I put it all at the end) You will note I had to duplicate some code twice since the first time we go to scene, we instead go to enterScene and then subsequently go to createScene.

local image
local imageOnce = false
local storyGroup

local function onSceneTouch( self, event )
if event.phase == “began” then
storyboard.gotoScene( false, “scene1”, “zoomOutInFadeRotate”, 1000 )
return true
end
end
– Called when the scene’s view does not exist:
function scene:createScene( event )
storyGroup = self.view
image = display.newImage( “Title-screen.jpg” )
storyGroup:insert( image )
image.touch = onSceneTouch
end
– Called immediately after scene has moved onscreen:
function scene:enterScene( event )
if imageOnce == false then
– following code should be in createScene
storyGroup = self.view
image = display.newImage( “Title-screen.jpg” )
storyGroup:insert( image )
image.touch = onSceneTouch
imageOnce = true
end
image:addEventListener( “touch”, image )
storyboard.purgeScene( “scene1” )
end

– Called when scene is about to move offscreen:
function scene:exitScene()
image:removeEventListener( “touch”, image )
display.remove( image )
end
– Called prior to the removal of scene’s “view” (display group)
function scene:destroyScene( event )
end
scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene”, scene )
scene:addEventListener( “exitScene”, scene )
scene:addEventListener( “destroyScene”, scene )

– Called when the scene’s view does not exist:
function scene1:createScene( event )
storyGroup = self.view
setup( Level, storyGroup )
Runtime:addEventListener( “enterFrame”, StartofGameLoop )
end

– Called immediately after scene has moved onscreen:
function scene1:enterScene( event )
storyboard.purgeScene( “scene” )
end

– Called when scene is about to move offscreen:
function scene1:exitScene()
removeGraphics( Level )
end

scene1:addEventListener( “createScene”, scene1 )
scene1:addEventListener( “enterScene”, scene1 )
scene1:addEventListener( “exitScene”, scene1 )
[import]uid: 108253 topic_id: 19806 reply_id: 77405[/import]

Hi @dennis20, I’m trying to do a very similar thing here, I think:

https://developer.anscamobile.com/forum/2012/01/16/trying-use-storyboard-one-scene

Basically, you want to have a module which can be reused for every “scene”, yes? I think this is a very good, modular way to work and would give more power to Corona than anyone really realises right now… [import]uid: 8271 topic_id: 19806 reply_id: 80827[/import]

I think I’ve managed it…

http://developer.anscamobile.com/forum/2012/01/16/trying-use-storyboard-one-scene#comment-80862 [import]uid: 8271 topic_id: 19806 reply_id: 80864[/import]

You can have two scenes in one file, in the exact manner as you described. Though I’m not sure why you’re not getting the “createScene” event for the first scene.

The new Game Center sample code shows an example of two storyboard scenes in one module (main.lua), but the “createScene” event works just fine.

Here’s a link to download the sample:
https://github.com/ansca/GameCenter

Please ensure that you have added your “createScene” event listener before you attempt to call storyboard.gotoScene() on that scene. [import]uid: 52430 topic_id: 19806 reply_id: 80960[/import]

Thanks Jonathan, but I think the real question here is “How do we make re-usable scene modules?”

For example, getting to the end of a game level and switching to the next level. Both levels would use the same level module/scene, but would be differentiated by the map data file (such as built in Tiled, etc.) [import]uid: 8271 topic_id: 19806 reply_id: 81010[/import]

[SOLVED]
Hi all,
And thank you all for your support and interest.
I finally solved this with help from Ansca bug support staff.
As you all suspected the order is VERY important when you put many storyboard scenes into one module (main.lua in my case)
Here is the correct statement order:

  1. local storyboard = require( “storyboard” )
    local scene0 = storyboard.newScene(“scene0”)
    local scene = storyboard.newScene(“scene”)
    local scene1 = storyboard.newScene(“scene1”)

  2. function scene:createScene( event )
    storyGroup = self.view
    end
    function scene:enterScene( event )
    end
    function scene:exitScene()
    end
    function scene:destroyScene( event )
    end

  3. scene:addEventListener( “createScene”, scene )
    scene:addEventListener( “enterScene”, scene )
    scene:addEventListener( “exitScene”, scene )
    scene:addEventListener( “destroyScene”, scene )

  4. storyboard.gotoScene( “scene”, “fade”, 400 )

This works and I am using it successfully. Now my createScene is called the first time as it should be. And everything now works as it should.
Thanks all again,
-Dennis

[import]uid: 108253 topic_id: 19806 reply_id: 81072[/import]