Scene changes, but get runtime error

Hello-
I’m trying to work with scenes, and I’m having a hard time from the start.
I created a test case where I’m creating button graphics that I wish to tap in order to move from scene to scene. I have the following code in my main.lua file- note that I was initially attempting to load in “scene_1” (scene_1.lua) directly from main.lua, but commented it out while attempting to make the tap work. When the commented line is uncommented, and the tap function removed, I get the same error. At any rate, the button tap changes the scene accordingly, but I keep getting a runtime error, which I’ve included below the main block of code.
[blockcode]
local storyboard = require “storyboard”
storyboard.purgeOnSceneChange = true
–storyboard.gotoScene( “scene_1”, “fade”, 400 )

local g = graphics.newGradient(
{ 132, 215, 250 },
{ 200, 200, 200 },
“down” )

local rect = display.newRect( 0, 0, display.contentWidth, display.contentHeight)
rect:setFillColor( g )
rect.x=display.contentWidth/2
rect.y=display.contentHeight/2
local circle1 = display.newCircle(0,0,10)
circle1:setFillColor(128,32,128)
local circle2 = display.newCircle(0,0,10)
circle2:setFillColor(32,15,128)

local circle3 = display.newCircle(0,0,10)
circle3:setFillColor(256,128,128)

local numText1 = display.newText(“1”, 200, 200, native.systemFont, 12)

local numText2= display.newText(“2”, 200, 200, native.systemFont, 12)

local numText3= display.newText(“3”, 200, 200, native.systemFont, 12)

local sceneText1 = display.newText(“Main Screen”, 200, 200, native.systemFont, 24)

local circle_num = {circle1, circle2, circle3}
local text_num = {numText1, numText2, numText3}

for i=1, #circle_num do
circle_num[i].y = display.contentHeight/2
circle_num[i].x = circle_num[i].width +i*circle_num[i].width
text_num[i].x = circle_num[i].x
text_num[i].y = circle_num[i].y
end

function circle1:tap(event)
storyboard.gotoScene(“scene_1” )
end
circle1:addEventListener(“tap”)
[/blockcode]

Here’s the error-
[blockcode]
Runtime error
?:0: attempt to concatenate global ‘sceneName’ (a nil value)
stack traceback:
[C]: ?
?: in function ‘gotoScene’
–filepath is my substitution for the actual filepath
(filepath)/main.lua:66: in function (filepath)/main.lua:65>
?: in function <?:229>
[/blockcode]

Any help or tips in what I’m doing incorrectly would be greatly appreciated! [import]uid: 194953 topic_id: 36268 reply_id: 336268[/import]

sounds like you might have an error in scene_1.lua.

[import]uid: 199310 topic_id: 36268 reply_id: 144082[/import]

Thanks for the reply. The code for scene_1.lua is virtually the same, except for a forward declaration of some variables. But here’s the code, just in case-
[blockcode]
–include the Corona “storyboard” module
local storyboard = require (“storyboard”)

–local scene=storyboard.newScene()
print(“Scene 1”)

local g, rect, circle1, circle2, circle3, numText1, numText2, numText3, sceneText1, circle_num, text_num

g = graphics.newGradient(
{ 132, 215, 250 },
{ 200, 200, 200 },
“down” )–rect
rect = display.newRect( 0, 0, display.contentWidth, display.contentHeight)
rect:setFillColor( g )
rect.x=display.contentWidth/2
rect.y=display.contentHeight/2

–circle1
circle1 = display.newCircle(0,0,10)
circle1:setFillColor(128,32,128)

–circle2
circle2 = display.newCircle(0,0,10)
circle2:setFillColor(32,15,128)

–circle3
circle3 = display.newCircle(0,0,10)
circle3:setFillColor(256,128,128)

–numText1

numText1 = display.newText(“1”, 200, 200, native.systemFont, 12)

–numText2

numText2= display.newText(“2”, 200, 200, native.systemFont, 12)

–numText3

numText3= display.newText(“3”, 200, 200, native.systemFont, 12)

–scenetText1

sceneText1 = display.newText(“Scene 1”, 200, 200, native.systemFont, 24)

–circle_num
circle_num = {circle1, circle2, circle3}

–text_num
text_num = {numText1, numText2, numText3}

for i=1, #circle_num do
circle_num[i].y = display.contentHeight/2
circle_num[i].x = circle_num[i].width +i*circle_num[i].width*i
text_num[i].x = circle_num[i].x
text_num[i].y = circle_num[i].y
end

[/blockcode] [import]uid: 194953 topic_id: 36268 reply_id: 144093[/import]

You need to take a look at the storyboard sample in the corona simulator. You are missing the functions that manage storyboard. You don’t need them in your main.lua but every scene after it you do.

[code]
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene
[/code] [import]uid: 208811 topic_id: 36268 reply_id: 144110[/import]

Thanks- I did look at the storyboard sample, as well as the tutorials, but could never find this spelled out explicitly. Additionally, there is a file called “scenetemplate.lua” in that batch of files- didn’t know whether there needed to be a file of this type in my project. As an aside, I think there needs to be a thoroughly detailed, step by step, single tutorial for the storyboard API, but I guess that’s a wishlist topic for a different forum, no? At any rate, I will definitely use your advice, and again, thanks for looking at it and responding. Will check back in once I have it running. [import]uid: 194953 topic_id: 36268 reply_id: 144171[/import]

Your storyboard scene isn’t a scene as @philjk19875 pointed out.

scenetemplate.lua exists so you can copy it to make your scene from and have all that structure. You’re right. We have a lot of information out there, but there appears that the idea that you have to have these scenes is missing.
[import]uid: 199310 topic_id: 36268 reply_id: 144182[/import]

sounds like you might have an error in scene_1.lua.

[import]uid: 199310 topic_id: 36268 reply_id: 144082[/import]

Thanks for the reply. The code for scene_1.lua is virtually the same, except for a forward declaration of some variables. But here’s the code, just in case-
[blockcode]
–include the Corona “storyboard” module
local storyboard = require (“storyboard”)

–local scene=storyboard.newScene()
print(“Scene 1”)

local g, rect, circle1, circle2, circle3, numText1, numText2, numText3, sceneText1, circle_num, text_num

g = graphics.newGradient(
{ 132, 215, 250 },
{ 200, 200, 200 },
“down” )–rect
rect = display.newRect( 0, 0, display.contentWidth, display.contentHeight)
rect:setFillColor( g )
rect.x=display.contentWidth/2
rect.y=display.contentHeight/2

–circle1
circle1 = display.newCircle(0,0,10)
circle1:setFillColor(128,32,128)

–circle2
circle2 = display.newCircle(0,0,10)
circle2:setFillColor(32,15,128)

–circle3
circle3 = display.newCircle(0,0,10)
circle3:setFillColor(256,128,128)

–numText1

numText1 = display.newText(“1”, 200, 200, native.systemFont, 12)

–numText2

numText2= display.newText(“2”, 200, 200, native.systemFont, 12)

–numText3

numText3= display.newText(“3”, 200, 200, native.systemFont, 12)

–scenetText1

sceneText1 = display.newText(“Scene 1”, 200, 200, native.systemFont, 24)

–circle_num
circle_num = {circle1, circle2, circle3}

–text_num
text_num = {numText1, numText2, numText3}

for i=1, #circle_num do
circle_num[i].y = display.contentHeight/2
circle_num[i].x = circle_num[i].width +i*circle_num[i].width*i
text_num[i].x = circle_num[i].x
text_num[i].y = circle_num[i].y
end

[/blockcode] [import]uid: 194953 topic_id: 36268 reply_id: 144093[/import]

You need to take a look at the storyboard sample in the corona simulator. You are missing the functions that manage storyboard. You don’t need them in your main.lua but every scene after it you do.

[code]
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene
[/code] [import]uid: 208811 topic_id: 36268 reply_id: 144110[/import]

Thanks- I did look at the storyboard sample, as well as the tutorials, but could never find this spelled out explicitly. Additionally, there is a file called “scenetemplate.lua” in that batch of files- didn’t know whether there needed to be a file of this type in my project. As an aside, I think there needs to be a thoroughly detailed, step by step, single tutorial for the storyboard API, but I guess that’s a wishlist topic for a different forum, no? At any rate, I will definitely use your advice, and again, thanks for looking at it and responding. Will check back in once I have it running. [import]uid: 194953 topic_id: 36268 reply_id: 144171[/import]

Your storyboard scene isn’t a scene as @philjk19875 pointed out.

scenetemplate.lua exists so you can copy it to make your scene from and have all that structure. You’re right. We have a lot of information out there, but there appears that the idea that you have to have these scenes is missing.
[import]uid: 199310 topic_id: 36268 reply_id: 144182[/import]

sounds like you might have an error in scene_1.lua.

[import]uid: 199310 topic_id: 36268 reply_id: 144082[/import]

Thanks for the reply. The code for scene_1.lua is virtually the same, except for a forward declaration of some variables. But here’s the code, just in case-
[blockcode]
–include the Corona “storyboard” module
local storyboard = require (“storyboard”)

–local scene=storyboard.newScene()
print(“Scene 1”)

local g, rect, circle1, circle2, circle3, numText1, numText2, numText3, sceneText1, circle_num, text_num

g = graphics.newGradient(
{ 132, 215, 250 },
{ 200, 200, 200 },
“down” )–rect
rect = display.newRect( 0, 0, display.contentWidth, display.contentHeight)
rect:setFillColor( g )
rect.x=display.contentWidth/2
rect.y=display.contentHeight/2

–circle1
circle1 = display.newCircle(0,0,10)
circle1:setFillColor(128,32,128)

–circle2
circle2 = display.newCircle(0,0,10)
circle2:setFillColor(32,15,128)

–circle3
circle3 = display.newCircle(0,0,10)
circle3:setFillColor(256,128,128)

–numText1

numText1 = display.newText(“1”, 200, 200, native.systemFont, 12)

–numText2

numText2= display.newText(“2”, 200, 200, native.systemFont, 12)

–numText3

numText3= display.newText(“3”, 200, 200, native.systemFont, 12)

–scenetText1

sceneText1 = display.newText(“Scene 1”, 200, 200, native.systemFont, 24)

–circle_num
circle_num = {circle1, circle2, circle3}

–text_num
text_num = {numText1, numText2, numText3}

for i=1, #circle_num do
circle_num[i].y = display.contentHeight/2
circle_num[i].x = circle_num[i].width +i*circle_num[i].width*i
text_num[i].x = circle_num[i].x
text_num[i].y = circle_num[i].y
end

[/blockcode] [import]uid: 194953 topic_id: 36268 reply_id: 144093[/import]

You need to take a look at the storyboard sample in the corona simulator. You are missing the functions that manage storyboard. You don’t need them in your main.lua but every scene after it you do.

[code]
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene
[/code] [import]uid: 208811 topic_id: 36268 reply_id: 144110[/import]

Thanks- I did look at the storyboard sample, as well as the tutorials, but could never find this spelled out explicitly. Additionally, there is a file called “scenetemplate.lua” in that batch of files- didn’t know whether there needed to be a file of this type in my project. As an aside, I think there needs to be a thoroughly detailed, step by step, single tutorial for the storyboard API, but I guess that’s a wishlist topic for a different forum, no? At any rate, I will definitely use your advice, and again, thanks for looking at it and responding. Will check back in once I have it running. [import]uid: 194953 topic_id: 36268 reply_id: 144171[/import]

Your storyboard scene isn’t a scene as @philjk19875 pointed out.

scenetemplate.lua exists so you can copy it to make your scene from and have all that structure. You’re right. We have a lot of information out there, but there appears that the idea that you have to have these scenes is missing.
[import]uid: 199310 topic_id: 36268 reply_id: 144182[/import]

sounds like you might have an error in scene_1.lua.

[import]uid: 199310 topic_id: 36268 reply_id: 144082[/import]

Thanks for the reply. The code for scene_1.lua is virtually the same, except for a forward declaration of some variables. But here’s the code, just in case-
[blockcode]
–include the Corona “storyboard” module
local storyboard = require (“storyboard”)

–local scene=storyboard.newScene()
print(“Scene 1”)

local g, rect, circle1, circle2, circle3, numText1, numText2, numText3, sceneText1, circle_num, text_num

g = graphics.newGradient(
{ 132, 215, 250 },
{ 200, 200, 200 },
“down” )–rect
rect = display.newRect( 0, 0, display.contentWidth, display.contentHeight)
rect:setFillColor( g )
rect.x=display.contentWidth/2
rect.y=display.contentHeight/2

–circle1
circle1 = display.newCircle(0,0,10)
circle1:setFillColor(128,32,128)

–circle2
circle2 = display.newCircle(0,0,10)
circle2:setFillColor(32,15,128)

–circle3
circle3 = display.newCircle(0,0,10)
circle3:setFillColor(256,128,128)

–numText1

numText1 = display.newText(“1”, 200, 200, native.systemFont, 12)

–numText2

numText2= display.newText(“2”, 200, 200, native.systemFont, 12)

–numText3

numText3= display.newText(“3”, 200, 200, native.systemFont, 12)

–scenetText1

sceneText1 = display.newText(“Scene 1”, 200, 200, native.systemFont, 24)

–circle_num
circle_num = {circle1, circle2, circle3}

–text_num
text_num = {numText1, numText2, numText3}

for i=1, #circle_num do
circle_num[i].y = display.contentHeight/2
circle_num[i].x = circle_num[i].width +i*circle_num[i].width*i
text_num[i].x = circle_num[i].x
text_num[i].y = circle_num[i].y
end

[/blockcode] [import]uid: 194953 topic_id: 36268 reply_id: 144093[/import]

You need to take a look at the storyboard sample in the corona simulator. You are missing the functions that manage storyboard. You don’t need them in your main.lua but every scene after it you do.

[code]
– “createScene” event is dispatched if scene’s view does not exist
scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished
scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins
scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be
– automatically unloaded in low memory situations, or explicitly via a call to
– storyboard.purgeScene() or storyboard.removeScene().
scene:addEventListener( “destroyScene”, scene )


return scene
[/code] [import]uid: 208811 topic_id: 36268 reply_id: 144110[/import]

Thanks- I did look at the storyboard sample, as well as the tutorials, but could never find this spelled out explicitly. Additionally, there is a file called “scenetemplate.lua” in that batch of files- didn’t know whether there needed to be a file of this type in my project. As an aside, I think there needs to be a thoroughly detailed, step by step, single tutorial for the storyboard API, but I guess that’s a wishlist topic for a different forum, no? At any rate, I will definitely use your advice, and again, thanks for looking at it and responding. Will check back in once I have it running. [import]uid: 194953 topic_id: 36268 reply_id: 144171[/import]