Changing Scenes

Hi there,

From my main.lua file, I’m trying to switch to another scene when a button is pushed. I’ve tried what I have posted below several times, but each time I run the code the debugger tells me the file I am relocating to cannot be found. Both the main.lua and the other file are in the same folder. What can I do to fix this problem? 

Thanks! 

display.setStatusBar( display.HiddenStatusBar ) local storyboard = require "storyboard" local function handleButtonEvent( event ) if ( "ended" == event.phase ) then storyboard.gotoScene( "teachCreateName.lua" ) --this file is in the same place as main.lua

Hello.  If you are not too far in your project I would suggest you switch to Composer instead of Storyboard.  Composer is Storyboard 2.0 and is the supported screen manager.  Storyboard is deprecated and we are not recommending people use it any longer.

That said, you don’t put the .lua on the file name for storyboard.gotoScene (or composer.gotoScene).   Also as a good practice, I would recommend having a staring scene perhaps called “menu.lua” and put all of your display items there you need for start up and let main.lua just be a launch point and place to initialize things like in app purchases, ads, gameNetwork, system events, etc.  In other words your main.lua could be as simple as:

local composer = require(“composer”)

composer.gotoScene(“menu”)

Then start with menu, build out your scene with your play button or other features and build up from there.

Rob

Thanks for the help! I’ve configured my code now so that main.lua contains only the following: 

local composer = require("composer") composer.gotoScene("mainHome")

And from there I want to relocate to mainHome. I still get the same error: 

File: ?

Attempt to concatenate global ‘sceneName’ (a nil value)

Am I doing something else incorrectly? Thanks! 

Is there more to the error?  More in your terminal/console window?

Also what does your mainHome.lua look like?

Rob

Hi.  We did a series on the ‘Composer’ scene manager over at the ‘Corona Geek’ show.

You can get the samples (many topics covered) HERE  This material may help you as you learn about Composer and scene management.

This page shows an index to the topics covered by the above linked content:

https://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts/composer_scene_manager

There is also more good stuff here (all hangout content that I curate):

https://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts

Thanks so much for the link to the corona geek videos; I think they will be very helpful! 

@Rob: I’ve pasted my error message below. The only thing in my mainHome.lua file is a button that should be displayed. Do I need to include something else for the composer to work? 

File: ?

Attempt to concatenate global ‘sceneName’ (a nil value)

stack traceback:

?: in function ‘gotoScene’

main.lua:3: in main chunk

Please post your mainHome.lua file. 

Here is the mainHome.lua file. It’s located in the same folder as my main.lua and other files. Thanks so much again for the help! 

local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then print( "Button was pressed and released" ) end end -- Create the widget local button1 = widget.newButton { left = 100, top = 200, id = "button1", label = "Default", onEvent = handleButtonEvent }

When you call composer.gotoScene(“somescene”) the file somescene.lua must be a Composer Scene.  That it is it has to require composer at the top, create the scene’s object.  Then there has to be a series of event handling functions defined that handle the various composer events like scene creation, scene showing and hiding, etc.  Visit this page:

http://docs.coronalabs.com/api/library/composer/index.html#scene-template

and copy the code from it.  That is the minimal code to make a scene file.  With what you have above, put the require widget line near the top.   The rest of the code would go inside the scene:create() function.

Rob

We just posted a tutorial with a sample complete game template.   It’s got a full composer based set of Lua files you can use to start building your game:

https://coronalabs.com/blog/2015/04/14/tutorial-the-basic-game-template/

Rob

Hello.  If you are not too far in your project I would suggest you switch to Composer instead of Storyboard.  Composer is Storyboard 2.0 and is the supported screen manager.  Storyboard is deprecated and we are not recommending people use it any longer.

That said, you don’t put the .lua on the file name for storyboard.gotoScene (or composer.gotoScene).   Also as a good practice, I would recommend having a staring scene perhaps called “menu.lua” and put all of your display items there you need for start up and let main.lua just be a launch point and place to initialize things like in app purchases, ads, gameNetwork, system events, etc.  In other words your main.lua could be as simple as:

local composer = require(“composer”)

composer.gotoScene(“menu”)

Then start with menu, build out your scene with your play button or other features and build up from there.

Rob

Thanks for the help! I’ve configured my code now so that main.lua contains only the following: 

local composer = require("composer") composer.gotoScene("mainHome")

And from there I want to relocate to mainHome. I still get the same error: 

File: ?

Attempt to concatenate global ‘sceneName’ (a nil value)

Am I doing something else incorrectly? Thanks! 

Is there more to the error?  More in your terminal/console window?

Also what does your mainHome.lua look like?

Rob

Hi.  We did a series on the ‘Composer’ scene manager over at the ‘Corona Geek’ show.

You can get the samples (many topics covered) HERE  This material may help you as you learn about Composer and scene management.

This page shows an index to the topics covered by the above linked content:

https://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts/composer_scene_manager

There is also more good stuff here (all hangout content that I curate):

https://github.com/roaminggamer/CoronaGeek/tree/master/Hangouts

Thanks so much for the link to the corona geek videos; I think they will be very helpful! 

@Rob: I’ve pasted my error message below. The only thing in my mainHome.lua file is a button that should be displayed. Do I need to include something else for the composer to work? 

File: ?

Attempt to concatenate global ‘sceneName’ (a nil value)

stack traceback:

?: in function ‘gotoScene’

main.lua:3: in main chunk

Please post your mainHome.lua file. 

Here is the mainHome.lua file. It’s located in the same folder as my main.lua and other files. Thanks so much again for the help! 

local widget = require( "widget" ) -- Function to handle button events local function handleButtonEvent( event ) if ( "ended" == event.phase ) then print( "Button was pressed and released" ) end end -- Create the widget local button1 = widget.newButton { left = 100, top = 200, id = "button1", label = "Default", onEvent = handleButtonEvent }

When you call composer.gotoScene(“somescene”) the file somescene.lua must be a Composer Scene.  That it is it has to require composer at the top, create the scene’s object.  Then there has to be a series of event handling functions defined that handle the various composer events like scene creation, scene showing and hiding, etc.  Visit this page:

http://docs.coronalabs.com/api/library/composer/index.html#scene-template

and copy the code from it.  That is the minimal code to make a scene file.  With what you have above, put the require widget line near the top.   The rest of the code would go inside the scene:create() function.

Rob

We just posted a tutorial with a sample complete game template.   It’s got a full composer based set of Lua files you can use to start building your game:

https://coronalabs.com/blog/2015/04/14/tutorial-the-basic-game-template/

Rob