Storyboard Help

Hello everybody,

I can go from the main.lua file to the sp.lua file.
I can also go from the sp.lua file to the spstart.lua file.
BUT I can’t go from the sp.lua file back to the main.lua file

Can anyone help me please?

main.lua:

[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local widget = require “widget”
display.setStatusBar( display.HiddenStatusBar )

local background = display.newImage ( “SkySoccer Grass.jpg” )

local ball = display.newImage( “SkySoccer Ball.gif” )
ball.x = display.contentWidth / 2

local white = display.newImage( “witteachtergrond.png” )
white.x = display.contentWidth / 1.3
white.y = display.contentWidth / 25

local myText = display.newText( “SkySoccer”, 0, 0, native.systemFont, 50 )
myText.x = display.contentCenterX
myText.y = display.contentWidth / 4.5
myText:setTextColor( 255, 0, 0 )

local myText = display.newText( “BroekieNetwork”, 0, 0, native.systemFont, 20 )
myText.x = display.contentWidth / 1.3
myText.y = display.contentWidth / 25
myText:setTextColor( 0, 0, 255 )

local function onButtonRelease( event )
local btn = event.target
storyboard.gotoScene( “sp” )
end

local button = widget.newButton{
id = “singleplayer”,
default = “single player.png”,
over = “single player2.png”,
onRelease = onButtonRelease
}
button.x = display.contentCenterX
button.y = display.contentWidth / 2

local function onButtonRelease2( event )
local btn = event.target
storyboard.gotoScene( “mp”, “fade”, 500 )
end

local button = widget.newButton{
id = “multiplayer”,
default = “multiplayer.png”,
over = “multiplayer2.png”,
onRelease = onButtonRelease2
}
button.x = display.contentCenterX
button.y = display.contentWidth / 1.4

local function onButtonRelease3( event )
local btn = event.target
storyboard.gotoScene( “pm”, “fade”, 500 )
end

local button = widget.newButton{
id = “promode”,
default = “pro mode.png”,
over = “pro mode2.png”,
onRelease = onButtonRelease3
}
button.x = display.contentCenterX
button.y = display.contentWidth / 1.07

local function onButtonRelease4( event )
local btn = event.target
storyboard.gotoScene( “tbm”, “fade”, 500 )
end

local button = widget.newButton{
id = “twoballsmode”,
default = “two balls mode.png”,
over = “two balls mode2.png”,
onRelease = onButtonRelease4
}
button.x = display.contentCenterX
button.y = display.contentWidth / 0.87

local function onButtonRelease5( event )
local btn = event.target
storyboard.gotoScene( “s”, “fade”, 500 )
end

local button = widget.newButton{
id = “shop”,
default = “shop.png”,
over = “shop2.png”,
onRelease = onButtonRelease5
}
button.x = display.contentCenterX
button.y = display.contentWidth / 0.73[/code]

sp.lua:

[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local widget = require “widget”
display.setStatusBar( display.HiddenStatusBar )

local background = display.newImage ( “uitlegbg.jpg” )

local myText = display.newText( “Single Player”, 0, 0, native.systemFont, 40 )
myText.x = display.contentCenterX
myText.y = display.contentWidth / 10
myText:setTextColor( 255, 0, 0 )

local myText = display.newRetinaText( “You have one ball and you have to keep the ball high as many times as you can”, 30, 70, 280, 220, native.systemFont, 22 )
myText:setTextColor( 255, 0, 0 )

local road = display.newImage( “roadklein.jpg” )
road.x = display.contentWidth / 5.5
road.y = display.contentWidth / 1.5

local beach = display.newImage( “beachklein.jpg” )
beach.x = display.contentWidth / 1.97
beach.y = display.contentWidth / 1.5

local house = display.newImage( “houseklein.jpg” )
house.x = display.contentWidth / 1.2
house.y = display.contentWidth / 1.5

local park = display.newImage( “parkklein.jpg” )
park.x = display.contentWidth / 3.3
park.y = display.contentWidth / 0.95

local stadium = display.newImage( “stadiumklein.jpg” )
stadium.x = display.contentWidth / 1.4
stadium.y = display.contentWidth / 0.95

local function onButtonRelease( event )
local btn = event.target
storyboard.gotoScene( “main” )
end

local button = widget.newButton{
id = “back”,
default = “back.png”,
over = “back2.png”,
onRelease = onButtonRelease
}
button.x = display.contentWidth / 4.2
button.y = display.contentWidth / 0.73

local function onButtonRelease2( event )
local btn = event.target
storyboard.gotoScene( “spstart” )
end

local button = widget.newButton{
id = “start”,
default = “start.png”,
over = “start2.png”,
onRelease = onButtonRelease2
}
button.x = display.contentWidth / 1.3
button.y = display.contentWidth / 0.73[/code] [import]uid: 203192 topic_id: 34027 reply_id: 334027[/import]

Actually, you can never go back to main.lua because main.lua is not a storyboard scene. Your main.lua is a place to initialize things and start up storyboard. I would recommend you make a new module called “splash.lua” (perhaps that’s what you intended “sp” to be), and move anything from main to it that displays and then main become something like:

local storyboard = require( "storyboard" )  
  
storyboard.gotoScene("splash")  

and never worry about getting back to main.

splash.lua of course will need to be a full scene:

----------------------------------------------------------------------------------  
--  
-- Your game name   
-- Copyright © 2012 Your Name. All rights reserved.  
--  
-- XXXX.lua  
--  
----------------------------------------------------------------------------------  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
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:overlayEnded( event )  
 local group = self.view  
end  
  
scene:addEventListener( "createScene", scene )  
scene:addEventListener( "enterScene", scene )  
scene:addEventListener( "exitScene", scene )  
scene:addEventListener( "destroyScene", scene )  
scene:addEventListener( "overlayEnded", scene )  
  
return scene  

You’re modules below are not using the standard storyboard structure, so you’re not letting storyboard do its job of creating scenes, moving them in and out as needed and cleaning up for you. For instance, all those display objects you create should be done inside the createScene() function and for each item you want to have managed, you need to go a:

group:insert(object) -- where object is whatever your creating  

[import]uid: 199310 topic_id: 34027 reply_id: 135327[/import]

Now I’ve this in my sp.lua file:

[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local widget = require “widget”
display.setStatusBar( display.HiddenStatusBar )

local background = display.newImage ( “uitlegbg.jpg” )

local myText = display.newText( “Single Player”, 0, 0, native.systemFont, 40 )
myText.x = display.contentCenterX
myText.y = display.contentWidth / 10
myText:setTextColor( 255, 0, 0 )

local myText = display.newRetinaText( “You have one ball and you have to keep the ball high as many times as you can”, 30, 70, 280, 220, native.systemFont, 22 )
myText:setTextColor( 255, 0, 0 )

local road = display.newImage( “roadklein.jpg” )
road.x = display.contentWidth / 5.5
road.y = display.contentWidth / 1.5

local beach = display.newImage( “beachklein.jpg” )
beach.x = display.contentWidth / 1.97
beach.y = display.contentWidth / 1.5

local house = display.newImage( “houseklein.jpg” )
house.x = display.contentWidth / 1.2
house.y = display.contentWidth / 1.5

local park = display.newImage( “parkklein.jpg” )
park.x = display.contentWidth / 3.3
park.y = display.contentWidth / 0.95

local stadium = display.newImage( “stadiumklein.jpg” )
stadium.x = display.contentWidth / 1.4
stadium.y = display.contentWidth / 0.95

local function goBack( event )
if event.phase == “release” then
storyboard.gotoScene(storyboard.getPrevious())
end
return true
end

local myButton = widget.newButton{
id = “btn001”,
left = 100,
top = 200,
default = “back.png”,
over = “back2.png”,
onEvent = goBack
}
group:insert( myButton )

local function Start( event )
if event.phase == “release” then
storyboard.gotoScene(“spstart”)
end
return true
end

local myButton2 = widget.newButton{
id = “btn002”,
left = 150,
top = 250,
default = “start.png”,
over = “start2.png”,
onEvent = Start
}
group:insert( myButton2 )[/code]

But it still doesn’t work [import]uid: 203192 topic_id: 34027 reply_id: 135331[/import]

Actually, you can never go back to main.lua because main.lua is not a storyboard scene. Your main.lua is a place to initialize things and start up storyboard. I would recommend you make a new module called “splash.lua” (perhaps that’s what you intended “sp” to be), and move anything from main to it that displays and then main become something like:

local storyboard = require( "storyboard" )  
  
storyboard.gotoScene("splash")  

and never worry about getting back to main.

splash.lua of course will need to be a full scene:

----------------------------------------------------------------------------------  
--  
-- Your game name   
-- Copyright © 2012 Your Name. All rights reserved.  
--  
-- XXXX.lua  
--  
----------------------------------------------------------------------------------  
  
local storyboard = require( "storyboard" )  
local scene = storyboard.newScene()  
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:overlayEnded( event )  
 local group = self.view  
end  
  
scene:addEventListener( "createScene", scene )  
scene:addEventListener( "enterScene", scene )  
scene:addEventListener( "exitScene", scene )  
scene:addEventListener( "destroyScene", scene )  
scene:addEventListener( "overlayEnded", scene )  
  
return scene  

You’re modules below are not using the standard storyboard structure, so you’re not letting storyboard do its job of creating scenes, moving them in and out as needed and cleaning up for you. For instance, all those display objects you create should be done inside the createScene() function and for each item you want to have managed, you need to go a:

group:insert(object) -- where object is whatever your creating  

[import]uid: 199310 topic_id: 34027 reply_id: 135327[/import]

Now I’ve this in my sp.lua file:

[code]local storyboard = require( “storyboard” )
local scene = storyboard.newScene()
local widget = require “widget”
display.setStatusBar( display.HiddenStatusBar )

local background = display.newImage ( “uitlegbg.jpg” )

local myText = display.newText( “Single Player”, 0, 0, native.systemFont, 40 )
myText.x = display.contentCenterX
myText.y = display.contentWidth / 10
myText:setTextColor( 255, 0, 0 )

local myText = display.newRetinaText( “You have one ball and you have to keep the ball high as many times as you can”, 30, 70, 280, 220, native.systemFont, 22 )
myText:setTextColor( 255, 0, 0 )

local road = display.newImage( “roadklein.jpg” )
road.x = display.contentWidth / 5.5
road.y = display.contentWidth / 1.5

local beach = display.newImage( “beachklein.jpg” )
beach.x = display.contentWidth / 1.97
beach.y = display.contentWidth / 1.5

local house = display.newImage( “houseklein.jpg” )
house.x = display.contentWidth / 1.2
house.y = display.contentWidth / 1.5

local park = display.newImage( “parkklein.jpg” )
park.x = display.contentWidth / 3.3
park.y = display.contentWidth / 0.95

local stadium = display.newImage( “stadiumklein.jpg” )
stadium.x = display.contentWidth / 1.4
stadium.y = display.contentWidth / 0.95

local function goBack( event )
if event.phase == “release” then
storyboard.gotoScene(storyboard.getPrevious())
end
return true
end

local myButton = widget.newButton{
id = “btn001”,
left = 100,
top = 200,
default = “back.png”,
over = “back2.png”,
onEvent = goBack
}
group:insert( myButton )

local function Start( event )
if event.phase == “release” then
storyboard.gotoScene(“spstart”)
end
return true
end

local myButton2 = widget.newButton{
id = “btn002”,
left = 150,
top = 250,
default = “start.png”,
over = “start2.png”,
onEvent = Start
}
group:insert( myButton2 )[/code]

But it still doesn’t work [import]uid: 203192 topic_id: 34027 reply_id: 135331[/import]