Storyboard

I need help for the storyboard apis between the levels, I don’t understand, so could someone explain me how it works? In my side, I have my main file, in the main file is a button “menu”, if I tap on it, it goes on the menu file. And in the menu file are 16 buttons, all the buttons are redirecting to the levels files, but, for example, only if we finished the level 3, we can play the level 4 … Then, I have a question, if we exit the game, is it going to save the score or not? If not how can I do it?
Thank you for your help :slight_smile:
Philippe

Hi Philippe.  These are all good questions.

First, you probably not think of main.lua as a scene.  You can initialize things there, but if you need a scene with a button that goes to your menu, you might want to have a scene called “splash.lua” that has your button to goto your menu scene.

Next, lets say a player finishes level3, simply do a storyboard.gotoScene(“level4”) to move on.  Your code in level3 should know if the player can goto level 4 or not and then you can have it go there for you.

Of course you will need to save some information (in memory for use while the game is playing and out to the file system in case the player shuts down the  game.  We just blogged about the way to track data between scenes in this weeks blogs about Globals:

http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Since you will have a data table of information that you might want to save, that could hold which levels you have unlocked and your high scores, I would recommend going through the community code and find some options that work for you.  I personally would recommend some code I wrote before I started working at Corona that quite a few people use.  See:

http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

That should give you a bit to explore.

Thanks alot Rob!

I’ll try to applie those informations,

I’ll also try to understand this :smiley: (I never did this before)

I will mark it solved when I’m done with this,

Philippe

So I tried, and I failed xD

So could please just show me how to do?

from main.lua to menu.lua by touching a button

There is the code I made:

*In main.lua*

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

local play = display.newImage(“play.png”);

 local function onObjectTouch( event )
    if event.phase == “began” then
    storyboard.gotoScene( “menu” )
    end
        return true
    end
    play:addEventListener( “touch”, onObjectTouch )

*In menu.lua*

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

This is the minimum code in your menu.lua for it to be recognized as a “scene”

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local utility = require("utility") function scene:createScene( event )     local group = self.view       --     -- Create your User Interface here.  Backgrounds, Buttons, etc.  Each item needs to be inserted into "group"     -- i.e.     local background = display.newRect(0,0,display.contentWidth,display.contentHeight)     background.x = display.contentCenterX     background.y = display.contentCenterY     group:insert(background)   end function scene:enterScene( event )     local group = self.view       -- put any native.newTextFields or any Runtime:addEventListeners, timers, voice overs, etc. here end function scene:exitScene( event )     local group = self.view       -- remove  any native.newTextFields or any Runtime:addEventListeners, timers, voice overs, etc. you     -- created in enterScene() end function scene:destroyScene( event )     local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

With out those four functions and those four scene:addEventListener’s and the return scene, storyboard won’t work.

Thanks Rob, it’s becomming clearer, there is another problem with this line of code “local utility = require(“utility”)” :

2013-06-08 11:18:06.081 Corona Simulator[666:f03] Runtime error:
2013-06-08 11:18:06.081 Corona Simulator[666:f03] module ‘utility’ not found:resource (utility.lu) does not exist in archive
    no field package.preload[‘utility’]
    no file ‘/Users/philippe/Desktop/Dev/Appster/utility.lua’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/utility.lua’
    no file ‘./utility.dylib’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/utility.dylib’
stack traceback:
 

what happend?

Oh, that’s a private library of mine that I forgot to take out when I copied the code from one of my templates.  You can delete the line:

local utility = require(“utility”)

Well thanks,

I followed your instructions, there is no error, the screen just became black :frowning:

Post your code please.

Hi Philippe.  These are all good questions.

First, you probably not think of main.lua as a scene.  You can initialize things there, but if you need a scene with a button that goes to your menu, you might want to have a scene called “splash.lua” that has your button to goto your menu scene.

Next, lets say a player finishes level3, simply do a storyboard.gotoScene(“level4”) to move on.  Your code in level3 should know if the player can goto level 4 or not and then you can have it go there for you.

Of course you will need to save some information (in memory for use while the game is playing and out to the file system in case the player shuts down the  game.  We just blogged about the way to track data between scenes in this weeks blogs about Globals:

http://www.coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/

Since you will have a data table of information that you might want to save, that could hold which levels you have unlocked and your high scores, I would recommend going through the community code and find some options that work for you.  I personally would recommend some code I wrote before I started working at Corona that quite a few people use.  See:

http://omnigeek.robmiracle.com/2012/02/23/need-to-save-your-game-data-in-corona-sdk-check-out-this-little-bit-of-code/

That should give you a bit to explore.

Thanks alot Rob!

I’ll try to applie those informations,

I’ll also try to understand this :smiley: (I never did this before)

I will mark it solved when I’m done with this,

Philippe

So I tried, and I failed xD

So could please just show me how to do?

from main.lua to menu.lua by touching a button

There is the code I made:

*In main.lua*

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

local play = display.newImage(“play.png”);

 local function onObjectTouch( event )
    if event.phase == “began” then
    storyboard.gotoScene( “menu” )
    end
        return true
    end
    play:addEventListener( “touch”, onObjectTouch )

*In menu.lua*

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

Sorry I’m a bit late, I wasn’t here this week :stuck_out_tongue:

local storyboard = require "storyboard" local scene = storyboard.newScene() -- forward declarations local bg function scene:createScene( event ) local group = self.view bg = display.newImage("background.jpg"); group:insert( bg ) end scene:addEventListener( "createScene", scene ) return scene

This is the minimum code in your menu.lua for it to be recognized as a “scene”

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() local utility = require("utility") function scene:createScene( event )     local group = self.view       --     -- Create your User Interface here.  Backgrounds, Buttons, etc.  Each item needs to be inserted into "group"     -- i.e.     local background = display.newRect(0,0,display.contentWidth,display.contentHeight)     background.x = display.contentCenterX     background.y = display.contentCenterY     group:insert(background)   end function scene:enterScene( event )     local group = self.view       -- put any native.newTextFields or any Runtime:addEventListeners, timers, voice overs, etc. here end function scene:exitScene( event )     local group = self.view       -- remove  any native.newTextFields or any Runtime:addEventListeners, timers, voice overs, etc. you     -- created in enterScene() end function scene:destroyScene( event )     local group = self.view end scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene

With out those four functions and those four scene:addEventListener’s and the return scene, storyboard won’t work.

can you try and center your image?

bg = display.newImage(“background.jpg”);

bg.x = display.contentCenterX

bg.y = display.contentCenterY

Thanks Rob, it’s becomming clearer, there is another problem with this line of code “local utility = require(“utility”)” :

2013-06-08 11:18:06.081 Corona Simulator[666:f03] Runtime error:
2013-06-08 11:18:06.081 Corona Simulator[666:f03] module ‘utility’ not found:resource (utility.lu) does not exist in archive
    no field package.preload[‘utility’]
    no file ‘/Users/philippe/Desktop/Dev/Appster/utility.lua’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/utility.lua’
    no file ‘./utility.dylib’
    no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/utility.dylib’
stack traceback:
 

what happend?

It still doesn’t work :frowning:

Maybe my corona build is too old?
I never updated it, the terminal is showing any error.

Just showing me where the file sandbox is.

So what should I do?

my buid is the 2012 971

Oh, that’s a private library of mine that I forgot to take out when I copied the code from one of my templates.  You can delete the line:

local utility = require(“utility”)

I just updated it, nothing much :frowning:

I tried this:

local storyboard = require "storyboard" local scene = storyboard.newScene() -- forward declarations local object1, object2 -- enterFrame event listener function local function onUpdate( event ) -- do something here end function scene:createScene( event ) local group = self.view object1 = display.newImage( "1.png" ) object2 = display.newImage( "2.png" ) group:insert( object1 ) group:insert( object2 ) end scene:addEventListener( "createScene", scene ) function scene:willEnterScene( event ) object1.isVisible = false object2.isVisible = false end scene:addEventListener( "willEnterScene", scene ) function scene:enterScene( event ) object1.isVisible = true object2.isVisible = true Runtime:addEventListener( "enterFrame", onUpdate ) end scene:addEventListener( "enterScene", scene ) function scene:exitScene( event ) object1.isVisible = true object2.isVisible = true Runtime:removeEventListener( "enterFrame", onUpdate ) end scene:addEventListener( "exitScene", scene ) function scene:didExitScene( event ) print( "This scene has fully transitioned out and is no longer the active scene." ) end scene:addEventListener( "didExitScene", scene ) return scene

From the tutorials on the ressources, also not working.

I don’t know why this happens,

could you please help me?

Thank you,

Philippe :slight_smile:

sorry I just wrote a post and it is complete nonsense!  Cant see how to delete…

also cant see why your code wont work.