Level Navigation

  1. add storyboard.isDebug = true to main.lua, after you require storyboard. This should give you warning messages if a scene can’t be found or has a problem in it.
  2. make sure the level scene (world1level1) is in the root folder along with main.lua

Is there a new message if you try it that way? [import]uid: 41884 topic_id: 34149 reply_id: 135813[/import]

after adding

storyboard.isDebug = true  

to the main.lua I get:

2012-12-19 17:01:20.354 Corona Simulator[16906:903]
Copyright © 2009-2012 C o r o n a L a b s I n c .
2012-12-19 17:01:20.354 Corona Simulator[16906:903] Version: 2.0.0
2012-12-19 17:01:20.354 Corona Simulator[16906:903] Build: 2012.971
2012-12-19 17:01:20.355 Corona Simulator[16906:903] The file sandbox for this project is located at the following folder:
(/Users/focuslab/Library/Application Support/Corona Simulator/Level Select Beta-99EAA31164CE3DBB365EDA023A4733F6)
2012-12-19 17:01:20.357 Corona Simulator[16906:903] WARNING: display.setStatusBarMode() not supported in the simulator for the current device
2012-12-19 17:01:26.420 Corona Simulator[16906:903] storyboard.level is… 1
2012-12-19 17:01:26.420 Corona Simulator[16906:903] storyboard.world is… 1
2012-12-19 17:01:26.421 Corona Simulator[16906:903] Runtime error
?:0: attempt to call method ‘dispatchEvent’ (a nil value)
stack traceback:
[C]: in function ‘dispatchEvent’
?: in function ‘gotoScene’
…focuslab/Desktop/Level Select Beta/levels.lua:23: in function ‘onRelease’
?: in function <?:3>
?: in function <?:229>

This is the terminal log from the time I run the game until I press World 1 then Level 1

world1level1.lua is in the root folder [import]uid: 72845 topic_id: 34149 reply_id: 135815[/import]

I agree that there is probably something simple being missed but from a forum glance I’m not sure. I’ll run the code tonight when I get home. The dispatchEvent part makes me think there is a typo in the scene construction, but it could also be widget related. [import]uid: 41884 topic_id: 34149 reply_id: 135818[/import]

Works like a dream, thank you! [import]uid: 72845 topic_id: 34149 reply_id: 136166[/import]

It sounds to me like the world name isn’t be constructed correctly. In other words a nil is getting passed in somewhere, which the only thing being passed in is scene name.

Try doing this:

 local world = "world"..storyboard.world.."level"..storyboard.level  
 print(world)   
 storyboard.gotoScene(world)   

and see if something is amis.
[import]uid: 199310 topic_id: 34149 reply_id: 135843[/import]

No clue why its not working : /
Anyone have an example of this working where you actually start a level not just posting text? [import]uid: 72845 topic_id: 34149 reply_id: 135849[/import]

Alright, sorry for the delay (family waits for no man). I loaded your code in, made a fake background.png, made a fake button.png…and the file loads perfectly.There’s a warning if I press on a button that the scene isn’t there, but that’s a far cry from your current situation.

(incidentally, the way you troubleshoot this stuff is to use --[[and --]] to encapsulate chunks of code that you think might be the problem. If you encapsulate and there are no errors, you know where the problem is lurking!)

( --[[–]] is the block version of just --, the latter of which has to be every line.)

The only exception I had to make was to hardcode storyboard.world = 1, but you’ve already shown that storyboard.world is being set…and you would get a concatenate error if it wasn’t.

Anyway, what I would do first is just – out the onRelease line from your button constructor. Does it still have an error? (We’re trying to narrow it down) I think Rob’s idea is also smart.

Let us know how it goes. [import]uid: 41884 topic_id: 34149 reply_id: 135853[/import]

 -- onRelease = buttonRelease   

No error [import]uid: 72845 topic_id: 34149 reply_id: 135855[/import]

Well, good news that the error goes away…

Now you need to rebuild the function as Rob described and then re-enable buttonRelease.

[code]local function buttonRelease(event)
local place = “world”…storyboard.world…“level”…storyboard.level
print("place = ", place)

storyboard.gotoScene(place)
end[/code]

What happens there? Still an error? What does the print statement show?

Also I see a typo in the tutorial. in main.lua it says storyboard.worlds = 0 when it should be storyboard.world = 0

We’ve almost got to the bottom of this…hang in there.

(and if there’s still a bug you may want to paste in your main.lua here…I feel like there is some sort of overwrite somewhere… [import]uid: 41884 topic_id: 34149 reply_id: 135859[/import]

After fixing main.lua and rebuilding buttonRelease I get:
2012-12-20 10:13:00.126 Corona Simulator[16906:903] place = world1level0
2012-12-20 10:13:00.126 Corona Simulator[16906:903] Cannot transition to scene: world1level0. There is either an error in the scene module, or you are attempting to go to a scene that does not exist. If you called storyboard.removeScene() on a scene that is NOT represented by a module, the scene must be re-created before transitioning back to it.
2012-12-20 10:13:00.127 Corona Simulator[16906:903] Runtime error
module ‘world1level0’ not found:resource (world1level0.lu) does not exist in archive
no field package.preload[‘world1level0’]
no file ‘/Users/focuslab/Desktop/Level Select Beta/world1level0.lua’
no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/world1level0.lua’
no file ‘./world1level0.dylib’
no file ‘/Applications/CoronaSDK/Corona Simulator.app/Contents/Resources/world1level0.dylib’
stack traceback:
[C]: ?
[C]: in function ‘error’
?: in function ‘gotoScene’
…focuslab/Desktop/Level Select Beta/levels.lua:20: in function ‘onRelease’
?: in function <?:3>
?: in function <?:229>

Here’s the main.lua

-----------------------------------------------------------------------------------------  
--  
-- main.lua  
--  
-----------------------------------------------------------------------------------------  
  
-- hide the status bar  
display.setStatusBar( display.HiddenStatusBar )  
  
-- include the Corona "storyboard" module  
local storyboard = require "storyboard"  
  
-- Store the selected world and level  
storyboard.world = 0  
storyboard.level = 0  
  
-- load menu screen  
storyboard.gotoScene( "worlds" )  
storyboard.isDebug = true  

Here’s the rebuild of the function just for good measure

local function buttonRelease(event)  
 local place = "world"..storyboard.world.."level"..storyboard.level  
 print("place = ", place)  
   
 storyboard.gotoScene(place)   
end  

Also I see that its looking for world1level0.lua so I also tried just changing world1level1.lua to world1level0.lua and got this message:

2012-12-20 10:17:16.376 Corona Simulator[16906:903] place = world1level0
2012-12-20 10:17:16.377 Corona Simulator[16906:903] Runtime error
?:0: attempt to call method ‘dispatchEvent’ (a nil value)
stack traceback:
[C]: in function ‘dispatchEvent’
?: in function ‘gotoScene’
…focuslab/Desktop/Level Select Beta/levels.lua:20: in function ‘onRelease’
?: in function <?:3>
?: in function <?:229>
[import]uid: 72845 topic_id: 34149 reply_id: 135891[/import]

derp…well the first bug is an obvious oversight on my part; I forgot to add in storyboard.level = event.target.id. Without it storyboard.level is always zero and storyboard will never find the file.

However!

Getting that error after you “fixed” the filename means that the problem is in the scene file you’re going to! So paste one of those in. We’ve almost got this figured out. [import]uid: 41884 topic_id: 34149 reply_id: 136028[/import]

Well it’s not like could see what the level code looks like in sim, anyway, as you use a lot of assets. :slight_smile:

  1. You’re using the sprite library, which has been deprecated for awhile. So I can’t really help with that apart from saying that you don’t keep it local?

(Actually, looking at this file I would guess you’re using something to generate the code, like level helper?)

  1. You use a really strange line that I haven’t encountered before. I guess it could be legit, but…
require("gnomies").getSpriteSheetData(); -- never seen requires that look at subtables...
  1. Under “floors” you have three identically named variables, which at best means two are being overwritten, at worst means there is an error there.

  2. …and…I’m going to stop looking for bugs right here. The real problem, and it’s fairly simple, is that storyboard only works going to storyboard scenes. You can’t just point at whatever file you want; the destination has to have the same createScene/enterScene/exitScene construction template that you already used to build the menu screen.

You don’t have to use all of the commands but you do need to have these ABSOLUTE basics, otherwise no scene is constructed and thus storyboard gives up, because it doesn’t “see” something to go to.

[code]local storyboard = require(“storyboard”)
local scene = storyboard.newScene()

– you can put all of your functions and stuff here

function scene:createScene( event )
– all of the display objects you make need to go in here or enterScene
end

scene:addEventListener( “createScene”, scene )

return scene[/code]

Well, I’m glad it was solvable! :wink: [import]uid: 41884 topic_id: 34149 reply_id: 136055[/import]

I really appreciate the help. As you can tell I’m a huge noob. Baby steps…baby steps. [import]uid: 72845 topic_id: 34149 reply_id: 136056[/import]

EDIT
[import]uid: 72845 topic_id: 34149 reply_id: 136045[/import]

One last question. Now that I know why my level won’t run I made a new level to run properly. However I used the code you recommended

storyboard.level = event.target.id  

Like so…

local function buttonRelease(event)  
 local place = "world"..storyboard.world.."level"..storyboard.level = event.target.id  
 print("place = ", place)  
   
 storyboard.gotoScene(place)   
end  

And my game locks at the world select screen. I changed the world1level1.lua to world1level0.lua and removed the code you said to use and the level loaded fine. Did I not apply the code you gave me properly?

Thanks again [import]uid: 72845 topic_id: 34149 reply_id: 136059[/import]

Because you can’t use equals in two places; that’s wrong in just about any kind of code. :wink: It should be:

[code]local function buttonRelease(event)
storyboard.level = event.target.id – sets level so it isn’t 0!
local place = “world”…storyboard.world…“level”…storyboard.level

storyboard.gotoScene(place)
return true – if you want, not sure if needed with the widget?
end[/code]

And remember, when you post problems here (and you will, for certain), post the error message. :slight_smile: [import]uid: 41884 topic_id: 34149 reply_id: 136093[/import]

Works like a dream, thank you! [import]uid: 72845 topic_id: 34149 reply_id: 136166[/import]

I’ve got a new dilemma. Not sure exactly why I’m getting the error but I’ll give you a run down of what’s going on before I post my report and luas. So I’m trying to expand on what we’ve been going over thus far and I wanted to add my own splash screen with a menu before loading the worlds.lua. I’ve added a “splash screen” but for some reason my “Play” button doesn’t change scene to the “Worlds” scene, and I’m getting errors before the splash screen appears.

TERMINAL REPORT:

2012-12-31 13:48:20.453 Corona Simulator[30126:903] WARNING: display.setStatusBarMode() not supported in the simulator for the current device
2012-12-31 13:48:20.454 Corona Simulator[30126:903] in load splashscreen file
2012-12-31 13:48:20.672 Corona Simulator[30126:903] Runtime error
?:0: attempt to concatenate global ‘sceneName’ (a nil value)
stack traceback:
[C]: ?
?: in function ‘gotoScene’
…s/focuslab/Desktop/Level Select Beta/main.lua:18: in main chunk
2012-12-31 13:48:20.672 Corona Simulator[30126:903] Runtime error:
2012-12-31 13:48:20.673 Corona Simulator[30126:903] ?:0: attempt to concatenate global ‘sceneName’ (a nil value)
stack traceback:
[C]: ?
?: in function ‘gotoScene’
…s/focuslab/Desktop/Level Select Beta/main.lua:18: in main chunk
2012-12-31 13:48:23.663 Corona Simulator[30126:903] Runtime error
…focuslab/Desktop/Level Select Beta/splashscreen.lua:48: attempt to call method ‘changeScene’ (a nil value)
stack traceback:
[C]: in function ‘changeScene’
…focuslab/Desktop/Level Select Beta/splashscreen.lua:48: in function <…focuslab select beta>
?: in function <?:229>

main.lua
<br>-----------------------------------------------------------------------------------------<br>--<br>-- main.lua<br>--<br>-----------------------------------------------------------------------------------------<br><br>-- hide the status bar<br>display.setStatusBar( display.HiddenStatusBar )<br><br>-- include the Corona "storyboard" module<br>local storyboard = require "storyboard"<br><br>-- Store the selected world and level<br>storyboard.world = 0<br>storyboard.level = 0<br><br>-- load menu screen<br>storyboard.gotoScene( "splashscreen" )<br>storyboard.isDebug = true<br>

and my splashscreen.lua
<br><br>local storyboard = require( "storyboard" )<br>display.setStatusBar(display.HiddenStatusBar)<br> print ("in load splashscreen file")<br> local localGroup = display.newGroup()<br><br>--BACKGROUND IMAGES <br> <br> local background = display.newImage("gnomiessplashbg.png")<br>localGroup:insert(background)<br>background.x = display.stageWidth / 2<br>background.y = display.stageHeight / 2 <br> <br>--media.playSound( "gnomiesmusic.mp3", true ) <br> <br> local backgroundbg2 = display.newImage("gnomiessplashbg2.png")<br>localGroup:insert(backgroundbg2)<br>backgroundbg2.x = display.stageWidth / 2<br>backgroundbg2.y = display.stageHeight / 2 <br>--BACKGROUND IMAGES END <br> <br> <br> <br> <br>--BUTTONS<br><br> local worlds = display.newImage("gnomiesPlaybutton.png" )<br> localGroup:insert(worlds)<br> <br>worlds.x = display.stageWidth / 1.9<br>worlds.y = display.stageHeight / 2.1 <br><br> <br>--END BUTTONS <br> <br> <br> <br> <br> <br> local function touched (event)<br> if ("ended" == event.phase) then<br> storyboard:changeScene( "worlds", "fade" ) <br> end <br> end<br> <br> worlds:addEventListener ("touch", touched)<br> <br>
And if I change
<br>storyboard.gotoScene( "splashscreen" )<br>
in the main.lua back to
<br>storyboard.gotoScene( "worlds" )<br>

everything works fine again, granted no splash screen. [import]uid: 72845 topic_id: 34149 reply_id: 136920[/import] </…focuslab>

It looks like to me that splashscreen.lua isn’t constructed as a storyboard module. All storyboard scenes must start with these two lines:

local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  

and must end with these lines:

scene:addEventListener( "createScene", scene )  
scene:addEventListener( "enterScene", scene )  
scene:addEventListener( "exitScene", scene )  
scene:addEventListener( "destroyScene", scene )  
  
return scene  

In addition you have to provide functions for each of those 4 event listeners (technically you don’t need to implement them, but if you don’t storyboard won’t work… In other words you could do everything in createScene and ignore the others, but you have to either do createScene or enterScene. If no storyboard has nothing to manage.

Since you are struggling with storyboard, lets go with these are required. The code for each of these functions looks like this:

function scene:createScene( event )  
 local group = self.view  
  
end  
  
function scene:enterScene( event )  
 local group = self.view  
  
end  
  
function scene:exitScene( event )  
 local group = self.view  
  
end  
  
function scene:destroyScene( event )  
 local group = self.view  
  
end  

Most of your work is going into the createScene function. For simple scenes, there is probably nothing to do in the other three. Your:

  
display.setStatusBar(display.HiddenStatusBar)  
 print ("in load splashscreen file")  
 local localGroup = display.newGroup()  
   
--BACKGROUND IMAGES   
  
 local background = display.newImage("gnomiessplashbg.png")  
localGroup:insert(background)  
background.x = display.stageWidth / 2  
background.y = display.stageHeight / 2   
  
--media.playSound( "gnomiesmusic.mp3", true )   
   
   
  
 local backgroundbg2 = display.newImage("gnomiessplashbg2.png")  
localGroup:insert(backgroundbg2)  
backgroundbg2.x = display.stageWidth / 2  
backgroundbg2.y = display.stageHeight / 2   
--BACKGROUND IMAGES END   
  
  
  
  
--BUTTONS  
   
 local worlds = display.newImage("gnomiesPlaybutton.png" )  
 localGroup:insert(worlds)  
  
worlds.x = display.stageWidth / 1.9  
worlds.y = display.stageHeight / 2.1   
   
   
   
   
--END BUTTONS   
   
   
   
   
   
 local function touched (event)  
 if ("ended" == event.phase) then  
 storyboard:changeScene( "worlds", "fade" )   
 end   
 end  
   
 worlds:addEventListener ("touch", touched)  
  

should be:

function scene:createScene( event )  
 local group = self.view  
  
 display.setStatusBar(display.HiddenStatusBar) -- print ("in load splashscreen file")  
 -- local localGroup = display.newGroup() -- -- need this since it's display.newGroup() is the "group"  
 -- four lines up.  
   
 --BACKGROUND IMAGES   
  
 local background = display.newImage("gnomiessplashbg.png")  
 group:insert(background) -- must be in the scene's view ("group") to be managed.  
 background.x = display.stageWidth / 2  
 background.y = display.stageHeight / 2   
  
 --media.playSound( "gnomiesmusic.mp3", true )   
  
 local backgroundbg2 = display.newImage("gnomiessplashbg2.png")  
 group:insert(backgroundbg2)  
 backgroundbg2.x = display.stageWidth / 2  
 backgroundbg2.y = display.stageHeight / 2   
 --BACKGROUND IMAGES END   
  
 --BUTTONS  
   
 local worlds = display.newImage("gnomiesPlaybutton.png" )  
 group:insert(worlds)  
  
 worlds.x = display.stageWidth / 1.9  
 worlds.y = display.stageHeight / 2.1   
   
 --END BUTTONS   
   
 local function touched (event)  
 if ("ended" == event.phase) then  
 storyboard:changeScene( "worlds", "fade" )   
 end   
 end  
   
 worlds:addEventListener ("touch", touched)  
end  

[import]uid: 199310 topic_id: 34149 reply_id: 136925[/import]

I appreciate the local group = self.view bit. I was using director before.
Just to make sure I’m on the right path here’s my splashscreen.lua now

local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
  
 print ("in load splashscreen file")  
  
  
function scene:createScene( event )  
 local group = self.view  
   
end  
   
function scene:enterScene( event )  
 local group = self.view  
   
end  
   
function scene:exitScene( event )  
 local group = self.view  
   
end  
   
function scene:destroyScene( event )  
 local group = self.view  
   
end  
  
  
function scene:createScene( event )  
 local group = self.view  
   
 display.setStatusBar(display.HiddenStatusBar)   
 print ("in load splashscreen file")  
  
   
 --BACKGROUND IMAGES   
  
 local background = display.newImage("gnomiessplashbg.png")  
 group:insert(background) -- must be in the scene's view ("group") to be managed.  
 background.x = display.contentWidth / 2  
 background.y = display.contentHeight / 2   
  
 --media.playSound( "gnomiesmusic.mp3", true )   
  
 local backgroundbg2 = display.newImage("gnomiessplashbg2.png")  
 group:insert(backgroundbg2)  
 backgroundbg2.x = display.contentWidth / 2  
 backgroundbg2.y = display.contentHeight / 2   
 --BACKGROUND IMAGES END   
  
 --BUTTONS  
   
 local worlds = display.newImage("gnomiesPlaybutton.png" )  
 group:insert(worlds)  
  
 worlds.x = display.contentWidth / 1.9  
 worlds.y = display.contentHeight / 2.1   
   
 --END BUTTONS   
   
 local function touched (event)  
 if ("ended" == event.phase) then  
 storyboard:changeScene( "worlds", "fade" )   
 end   
 end  
   
 worlds:addEventListener ("touch", touched)  
end  
  
  
  
scene:addEventListener( "createScene", scene )  
scene:addEventListener( "enterScene", scene )  
scene:addEventListener( "exitScene", scene )  
scene:addEventListener( "destroyScene", scene )  
   
return scene  

Not 100% sure if this is the proper order to add the function scenes and add event listeners in. If it is correct I’m still getting this message in the terminal when I click the “play” button on the splash screen.

2012-12-31 14:54:19.669 Corona Simulator[30126:903] Runtime error
…focuslab/Desktop/Level Select Beta/splashscreen.lua:68: attempt to call method ‘changeScene’ (a nil value)
stack traceback:
[C]: in function ‘changeScene’
…focuslab/Desktop/Level Select Beta/splashscreen.lua:68: in function <…focuslab select beta>
?: in function <?:229>
Appreciate your help
[import]uid: 72845 topic_id: 34149 reply_id: 136932[/import] </…focuslab>