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

I suspect you are running into a problem from using Global variables. Your “background” is a global. If your start.lua scene also has a variable called background that is global, when you purge your start scene with: storyboard.purgeScene(“start”) it will remove everything in start scene. If start scene has a global named background, it gets removed and later when you try to leave this scene, it can’t find background to remove it.

Globals are evil and you shouldn’t use them unless you absolutely have to.

People use globals as a way to get around dealing with scope. We have a tutorial that tries to explain scope and how to properly code your app so that you can use local variables instead of globals.  https://coronalabs.com/blog/2015/06/16/tutorial-scope-for-beginners/

In your case, at the very top you have this line:

-- background

change that to:

local background

That will properly scope your background variable in your module so it can be used inside different functions and not run into problems with globals.

Since I can’t see start.lua, I’m only guessing that this the problem because that’s the only reason I can see why background wouldn’t be a display object at that point in your code.

Yes you right.

But if I put local then Corona Simulator tells me that there is an error whit listener, line 36.

local storyboard = require ("storyboard") local scene = storyboard.newScene() local cambio = 0 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) local tasto1 = display.newImage("tastostart.png") 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
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