Corona Runtime Error, storyboard.lua:617: attempt to index local 'bounds' (a nil value)

local storyboard = require ("storyboard") local scene = storyboard.newScene() local cambio = 0 local tasto1 --\<---- make it local here so all children functions can see it. function scene:createScene(event) local group = self.view local gameMusic = audio.loadStream( "base\_ballshot.mp3" ) local background\_start = display.newImage("Menubackground.png") background\_start.x = display.contentWidth \* 0.5 background\_start.y = 230 group:insert(background\_start) tasto1 = display.newImage("tastostart.png") --\<----- take off the local here tasto1.x = display.contentWidth \* 0.5 -180 tasto1.y = 250 --local gameMusicChannel = audio.play( gameMusic, { loops = -1 } ) end function start(event) if event.phase == "began" then storyboard.gotoScene("livello1", "fade", 400) storyboard.purgeScene("start") end end function scene:enterScene(event) storyboard.purgeScene("gameover") tasto1:addEventListener("touch", start) end function scene:exitScene(event) tasto1:removeEventListener("touch", start) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene 

I made two changes to illustrate this. Look for the two lines with --<-------

Thanks Rob, number one. How Can I remove timer at the end of scene?

Because if in the there isn’t any timer I don’t have the error ‘Content Bounds a nil value’.

I don’t see a timer in your code above. So I’m going to give you an example:

local mySuperTimer --\<----- put this line of code near the top, not inside any function.

This is is needed because we are going to create the timer inside of one function but we need to cancel it inside another function. Declaring this at the top of the module outside of any function makes the variable visible to the whole module/scene.

Inside your scene:enterScene() function:

mySuperTimer = timer.performWithDelay( 1000, functionToRun )

You’re going to put your timer function, storing the handle to the function in the variable on the left inside the “enterScene” event function. Do not put it in createScene(). Why? Well createScene() happens before the scene is on the screen. I don’t think you want your timer running before your users can see the scene.

Inside your scene:exitScene() function

timer.cancel( mySuperTimer )

This will cancel the timer before the scene transitions away and things start getting purged.

Rob

Can we see the code around livello1.lua line 400?

Also are you inserting all of your display objects you create in scene:createScene() into the scene’s group?

Rob

Hi rob, yes I insert all objects.

this is the code between line 396 and line 400:

local function gameover()

  if collisione_personaggio_var == 1 then

    rimozione = 0

    storyboard.purgeScene(“start”)

    storyboard.gotoScene( “gameover”, { effect = “fade”, time = 300 } )

Last instruction is line.400

Thanks.

Frequently those errors are due to errors in the scene you are going to. You will need to look at gameover.lua and see if you can spot any problems. Is “start” the scene you are currently in?

Storyboard isn’t supported any longer. We recommend converting to Composer.

Currently I’m in “livello_1”, the code works so: “start”-“livello_1”-“gameover”, from scene “gameover” you come back in scene “start”.

I don’t find any error  :frowning:

Looking at the code for Storyboard, this is a condition where there are no display objects having been inserted into the scene. It’s trying to get the contentBounds of the current scene’s group and it’s not finding a value for it. This tells me the group is empty.

Since you’ve not posted any code, I don’t know which template you’re using for scenes, but you should have in scene:createScene() something that looks like:
 

function scene:createScene( event ) local group = self.view

In the app I took this from, “group” is the display group you are supposed to insert things in too. Sometimes it might be called “screenGroup” or something else. When you create any display objects like say the background for the scene you must insert them:

&nbsp;&nbsp;&nbsp;&nbsp; local background = display.newRect(0, 0, display.contentWidth, display.contentHeight) &nbsp;&nbsp;&nbsp;&nbsp; group:insert( background )

Check to make sure you are inserting things into the scene you are leaving and the scene you are going to.

A little piece of code:

function scene:createScene(event)

local screenGroup = self.view

background = display.newImage(“sfondo.png”)

background.x = 250

background.y = 100

screenGroup:insert(background)

Floor = display.newImage(“Floor.png”)

Floor.x = 220

Floor.y = 515

physics.addBody( Floor, “static”)

screenGroup:insert(Floor)

What about the scene you’re going to?

This is the full code about scene “start.lua”:

local storyboard = require (“storyboard”)

local scene = storyboard.newScene()

function scene:createScene(event)

local group = self.view

local gameMusic = audio.loadStream( “base_ballshot.mp3” )

local background_start = display.newImage(“Menubackground.png”)

background_start.x = display.contentWidth * 0.5 

background_start.y = 230

group:insert(background_start)

 tasto1 = display.newImage(“tastostart.png”)

tasto1.x = display.contentWidth * 0.5 -180

tasto1.y = 250

group:insert(tasto1)

local gameMusicChannel = audio.play( gameMusic, { loops = -1 } )

end

function start(event)

if event.phase == “began” then

storyboard.purgeScene(“livello1”)

storyboard.gotoScene(“livello1”, “fade”, 400)

end

end

function scene:enterScene(event)

storyboard.purgeScene(“livello1”)

 tasto1:addEventListener(“touch”, start)

end

function scene:exitScene(event)

display.remove(background)

display.remove(tasto1)

tasto1:removeEventListener(“touch”, start)

end

function scene:destroyScene(event)

end

scene:addEventListener(“createScene”, scene)

scene:addEventListener(“enterScene”, scene)

scene:addEventListener(“exitScene”, scene)

scene:addEventListener(“destroyScene”, scene)

return scene

Please use the blue <> button to open a window to paste your code into. I’m more interested in “gameover.lua”.

I don’t konw what you mean whit <> blu button…sorry.

This is the full code about “gameover.lua”:

local storyboard = require (“storyboard”)

local scene = storyboard.newScene()

– background

function scene:createScene(event)

local group = self.view

 sfondo_gameover = display.newImage(“gameover.png”)

sfondo_gameover.x = display.contentWidth * 0.5 

sfondo_gameover.y = 230

group:insert(sfondo_gameover)

–tasto1.isVisible = true

end

function start(event)

if event.phase == “began” then

storyboard.purgeScene(“livello1”)

storyboard.purgeScene(“start”)

storyboard.gotoScene(“start”, “fade”, 400)

end

end

function scene:enterScene(event)

storyboard.purgeScene(“livello1”)

sfondo_gameover:addEventListener(“touch”, start)

    

end

function scene:exitScene(event)

sfondo_gameover:removeEventListener(“touch”, start)

end

function scene:destroyScene(event)

end

scene:addEventListener(“createScene”, scene)

scene:addEventListener(“enterScene”, scene)

scene:addEventListener(“exitScene”, scene)

scene:addEventListener(“destroyScene”, scene)

return scene

When you are typing a response here in the forums, right above where you type are buttons to Bold, Italicize, Underline, etc. This is the formatting bar. In the middle is an icon that is a blue <> shape between the photo icon and the speech bubble icon. Click it. Paste your code into the window and click Okay.

This will format your code properly.

It looks like you are inserting your gameover.png into the scene correctly. The only thing would be if that image doesn’t exist.

What version of Corona SDK are you using?

The image exist… I’m using Corona SDK v2016.2830.

Is there another way to change sceene?

Yes. Use Composer.  See: https://docs.coronalabs.com/guide/system/composer/index.html

Composer is Storyboard’s newer, better brother or Storyboard 2.0 if that helps you imagine what it is. It is however not code compatible with Storyboard. See the Migration guide.

Rob

Hi Rob, I solved that problem, thanks.

But now I have another error:

gameover.lua:30: attempt to call method ‘addEventListener’ (a nil value).

This is the error, I don’t know how fix it.

Sorry, I forgot to say that this error appear only when I try to go to a scene used before.

What is line 30 of gameover.lua? Can you post the code around it? Normally if we can’t find the function addEventListener, which is what this error is saying it’s because the object doesn’t exist. Perhaps if you’re adding this to an image, that image failed to load for some reason (filename not right?).

Rob

local storyboard = require ("storyboard") local scene = storyboard.newScene() local cambio = 0 -- background function scene:createScene(event) local group = self.view background = display.newImage("Gameover.png") background.x = display.contentWidth \* 0.5 background.y = 230 group:insert(background) end function start(event) if event.phase == "ended" and cambio == 0 then storyboard.gotoScene("start") cambio = 1 end end function scene:enterScene(event) storyboard.purgeScene("start") background:addEventListener("touch", start) end function scene:exitScene(event) background:removeEventListener("touch", start) end function scene:destroyScene(event) end scene:addEventListener("createScene", scene) scene:addEventListener("enterScene", scene) scene:addEventListener("exitScene", scene) scene:addEventListener("destroyScene", scene) return scene

This all scene ‘gameover’