Storyboard Issue

When trying to move from one scene to another i get an error.  it works fine with my other scenes but not this one… Here is what I got:

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

function startGame(event)
if event.phase == “ended” then
storyboard.gotoScene(“game”)
end
end

function scene:enterScene(event)
target:addEventListener(“touch”, startGame)
end

function scene:exitScene(event)
target:removeEventListener(“touch”,startGame)
storyboard.purgeScene(“instructions”)
end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)

return scene[/lua]

What is the error?

oh sorry.

2014-05-01 21:30:15.558 Corona Simulator[8059:507] Runtime error

assertion failed!

stack traceback:

[C]: in function ‘error’

?: in function ‘gotoScene’

instructions.lua:6: in function <instructions.lua:4>

?: in function <?:218>

function startGame(event) – line 4

if event.phase == “ended” then

storyboard.gotoScene(“game”)  – line 6

    end

end

It’s difficult out of context to say. It looks all right.

What I’d do as a first step, is replace the storyboard.gotoScene() with print(“Hi, I’m going to scene”).  Run that and see what happens.

If it prints out 'Hi I’m going to scene then it may actually be in the scene you are going to.

The actual message is an internal Corona thing, it’s not your code that is generating it but you have upset storyboard somehow. Some programmers write things like:

assert(x \> 0,"Oh stuff, x should be positive at this point")

when developing code that is potentially challenging or that people might provide parameters for wrongly. A very simple example would be.

function doubleMe(n) &nbsp;assert(type(n) == "number", "Oi ! I want a number") &nbsp;return n + n end

which checks that it’s getting the right thing. This is a slightly silly example, but if  you do this and pass it a table you get a better error message than the trying to do maths with a table message. You can use things like duck typing when passing more complicated modules and objects about.

try defining a createScene method for your listener

I think Dave is right.  Your createScene function seems to be missing.  Look at the default storyboard template.  These are really the minimum settings for a scene.

function scene:createScene(event)

local sceneGroup = self.view

insert all of the code here…

return scene

end

scene:addEventListener(“createScene”, scene)

is that what you are saying i need? i already have that all in there…

I did the print inside the storyboard.goto and it prints what i put to the terminal. where else should i look for my error?

Here is all the code from the instructions.lua

[lua]local storyboard = require(“storyboard”)

local scene = storyboard.newScene()

function scene:createScene(event)

local sceneGroup = self.view

background = display.newImageRect(“hay.jpg”,1280,1920)
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
sceneGroup:insert(background)

target = display.newImageRect(“bullseye.png”,160,160)
target.x = display.contentCenterX
target.y = display.contentCenterY
sceneGroup:insert(target)

topText1 = display.newText(“Touch As Many Targets”,display.contentCenterX, display.contentCenterY - 300, system.nativeFont, 50)
topText2 = display.newText(“As You Can”,display.contentCenterX, display.contentCenterY - 250, system.nativeFont, 50)
topText1:setFillColor(0,0,0)
topText2:setFillColor(0,0,0)

bottomText1 = display.newText(“Before Time Runs Out,”,display.contentCenterX, display.contentCenterY + 200, system.nativeFont, 50)
bottomText2 = display.newText(“But Don’t Miss”,display.contentCenterX, display.contentCenterY + 250, system.nativeFont, 50)
bottomText1:setFillColor(0,0,0)
bottomText2:setFillColor(0,0,0)

tap = display.newText(“TAP”, display.contentCenterX, display.contentCenterY, system.nativeFont, 50)
tap:setFillColor(0,0,0)

end

function startGame(event)
if event.phase == “ended” then
storyboard.gotoScene(“game”)
end
end

function scene:enterScene(event)
target:addEventListener(“touch”, startGame)
end

function scene:exitScene(event)
target:removeEventListener(“touch”,startGame)
storyboard.purgeScene(“instructions”)
end

scene:addEventListener(“createScene”, scene)
scene:addEventListener(“enterScene”, scene)
scene:addEventListener(“exitScene”, scene)

return scene[/lua]

All of the objects you are creating in your createScene are global.  If you have used these names in other modules, like “background”, they will stomp on each other and you have have one scene removing objects in this scene.  I would clean that up first.

Next I think it’s a best practice to call purgeScene() or removeScene() just before you goto another scene.  I don’t like putting purge and remove’s in the exitScene.  You end up trying to remove your self before you have been transitioned away.

Rob

Ok so that seemed to fix most of it.  Made them all local and moved the prugeScene() in the function instead of the enterScene.  The game works until I try to go to the score screen when the game ends and I get this error:

2014-05-04 00:46:06.398 Corona Simulator[10178:507] Runtime error

?:0: attempt to index field ‘contentBounds’ (a nil value)

stack traceback:

?: in function ‘?’

?: in function ‘gotoScene’

game.lua:67: in function ‘_listener’

?: in function <?:141>

?: in function <?:218>

this is the code it is referring to:

[lua]local function timerDown()
timeLimit = timeLimit-1
timeLeft.text = timeLimit
if(timeLimit==0)then
storyboard.purgeScene(“game”)
storyboard.gotoScene(“restart”) – Line 67
end
end[/lua]

I put a print in the storyboard.gotoScene to see if the code gets that far and it does.  Not sure why it works on every scene but this one…

What I meant by purging the scene before you go to it was more like this:

storyboard.purgeScene(“restart”)

storyboard.gotoScene(“restart”)

 

It looks like you’re still trying to purge the scene you’re in.

 

As for the error, it’s likely something in your restart.lua scene.

What is the error?

oh sorry.

2014-05-01 21:30:15.558 Corona Simulator[8059:507] Runtime error

assertion failed!

stack traceback:

[C]: in function ‘error’

?: in function ‘gotoScene’

instructions.lua:6: in function <instructions.lua:4>

?: in function <?:218>

function startGame(event) – line 4

if event.phase == “ended” then

storyboard.gotoScene(“game”)  – line 6

    end

end

It’s difficult out of context to say. It looks all right.

What I’d do as a first step, is replace the storyboard.gotoScene() with print(“Hi, I’m going to scene”).  Run that and see what happens.

If it prints out 'Hi I’m going to scene then it may actually be in the scene you are going to.

The actual message is an internal Corona thing, it’s not your code that is generating it but you have upset storyboard somehow. Some programmers write things like:

assert(x \> 0,"Oh stuff, x should be positive at this point")

when developing code that is potentially challenging or that people might provide parameters for wrongly. A very simple example would be.

function doubleMe(n) &nbsp;assert(type(n) == "number", "Oi ! I want a number") &nbsp;return n + n end

which checks that it’s getting the right thing. This is a slightly silly example, but if  you do this and pass it a table you get a better error message than the trying to do maths with a table message. You can use things like duck typing when passing more complicated modules and objects about.

try defining a createScene method for your listener

I think Dave is right.  Your createScene function seems to be missing.  Look at the default storyboard template.  These are really the minimum settings for a scene.

function scene:createScene(event)

local sceneGroup = self.view

insert all of the code here…

return scene

end

scene:addEventListener(“createScene”, scene)

is that what you are saying i need? i already have that all in there…