Storyboard Issue

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.