attempt to index field 'contentBounds' (a nil value)

When I do that I get the former error 

Whether I do this code or the code I fount I’m still getting the error 

You need to post your updated code. We can’t guess at what you’ve actually done. And you need to post the exact error again as something might be different there since your line numbers are likely different.

Rob

This is what I have and I’m not getting any errors :

restart.lua:

function scene:show(event) local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") end composer.removeScene( "game" ) Runtime:addEventListener("touch", touchScreen) end scene:addEventListener( "show" )

game.lua:

function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") end end scene:addEventListener( "show" )

You actually need to do things people advise you (e.g. @roaminggamer).  If you do not follow correct advice then people will stop helping you.

You have…

function scene:show(event) local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") end composer.removeScene( "game" ) Runtime:addEventListener("touch", touchScreen) end scene:addEventListener( "show" )

it should be

function scene:show(event) local phase = event.phase if ( phase == "will" ) then print("Phase started") elseif ( phase == "did" ) then print("phase showing objects") composer.removeScene(&nbsp;"game"&nbsp;) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\<-- NOTE THIS end Runtime:addEventListener("touch", touchScreen) end scene:addEventListener( "show" )

I am having this same exact problem on the same practice project . I thought the answer sgs and roaminggamer gave me was correct but I guess it’s not because I am having the same problem . I tried switching the code around and trying to take some things out but none of that helped . 

game.lua:

-- requires local composer = require( "composer" ) local scene = composer.newScene() local physics = require("physics") physics.start() physics.setGravity(0,9.8) local top = display.contentCenterY - display.actualContentHeight/2 local bottom = top + display.actualContentHeight local left = display.contentCenterX - display.actualContentWidth/2 local right = left + display.actualContentWidth -- background function scene:create(event) local screenGroup = self.view local randomImage = math.random(1,33) local background = display.newImageRect("images/background"..randomImage..".jpg",display.contentWidth,display.contentHeight) background.x = display.contentCenterX background.y = display.contentCenterY screenGroup:insert(background) end local timeLimit = 100 local currentTime = 0 local timerUpTimer currentTimeText = display.newText(currentTime, 160, 20, native.systemFontBold, 20) currentTimeText:setTextColor(0,1,1) local function timerUp() currentTime = currentTime + 1 currentTimeText.text = currentTime if currentTime \>= timeLimit then display.remove(currentTimeText) timer.cancel(timerUpTimer) print("Good job beating the game !") end end timerUpTimer = timer.performWithDelay(1000, timerUp, 0) timerr = timer.performWithDelay(1000,timerDown,timeLimit) local allBalloons = {} local timerHandle local function onTouch( self, event ) allBalloons[self] = nil display.remove(self) return true end local options = { effect = "fade", time = 400 } -- This function stops the game local function endGame() -- Stop the timer timer.cancel(timerHandle) -- Iterate over 'allBalloons' table and destroy all balloons for k,v in pairs( allBalloons ) do display.remove(v) end composer.gotoScene("restart",options) end -- Generic/Common enterFrame listener used by each balloon local function enterFrame( self ) -- End the Game if any balloon's CENTER falls below the bottom of the screen if( self.y \>= bottom ) then timer.cancel(timerUpTimer) endGame() end end -- Generic/Common finalize event listener used by each balloon local function finalize( self ) Runtime:removeEventListener("enterFrame",self) end local function createBalloon( ) -- Randomly create one of five balloon images local imgNum = math.random( 1, 5 ) local tmp = display.newImageRect( "balloon" .. imgNum .. ".png", 195/5, 282/5 ) -- Store reference to balloon object in allBalloons table allBalloons[tmp] = tmp -- Randomly place the balloon tmp.y = top-50 tmp.x = math.random( left + 50, right - 50 ) -- Scale it to make a 'smaller' balloon --tmp:scale( 0.1, 0.1 ) -- add a touch listener tmp.touch = onTouch tmp:addEventListener( "touch" ) -- Give it a body so 'gravity' can pull on it physics.addBody( tmp, { radius = tmp.contentWidth/2} ) -- Give the body a random rotation tmp.angularVelocity = math.random( -180, 180 ) -- Give it drag so it doesn't accelerate too fast tmp.linearDamping = 1.5 -- Self destruct in 5 seconds timer.performWithDelay( 5000, function() allBalloons[tmp] = nil display.remove( tmp ) end ) -- attach generic enterFrame listener and listen for it tmp.enterFrame = enterFrame Runtime:addEventListener("enterFrame", tmp) -- attach generic finalize listener and listen for it tmp.finalize = finalize tmp:addEventListener("finalize") end -- Create a new baloon every 1/2 second forever timerHandle = timer.performWithDelay( 160, createBalloon, -3 ) function scene:show(event) local sceneGroup = self.view composer.removeScene("restart") end function scene:hide(event) local sceneGroup = self.view end function scene:destroy(event) local sceneGroup = self.view end scene:addEventListener("create", scene) scene:addEventListener("show", scene) scene:addEventListener("hide", scene) scene:addEventListener("destroy", scene) return scene

I scan this code day and night and I see absolutely no error ,.

Hello any help ?

I just downloaded Agent Ransack and ran a search in the folder of my app and nothing cam up for contentBounds .

I just checked the docs but I’m doing everything right .

Right you need to stop right there if you ever want help on the forums again.  We have all helped you but you ignore our help.

You say your code is error free but it is so obviously not and we have told you hundreds of times what the problem is. But one more time (maybe you will understand it this time?)

function scene:show(event)&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;local sceneGroup = self.view &nbsp;&nbsp;&nbsp;&nbsp;composer.removeScene("restart") end

Note the line (below) that I know for a fact 4+ people have pointed out is causing your issues

composer.removeScene("restart")

You are running that twice and therefore Corona (@rob needs some hardening for sure) is trying to remove the scene twice!

I don’t like being horrible but you are really trying to run before you walk here!

Here is an idea, if you want to learn then start from scratch, write a line of code and then run it, if no errors then write another line of code and test it and then repeat.

When I remove that line from my game.lua file, my timer doesn’t show . Going from start to game the timer shows up and functions properly but when I go from restart to game the timer shows at zero and then disappears . 

When I do this code :

function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("show started") elseif ( phase == "did" ) then print("show showing objects") composer.removeScene( "restart" ) end end scene:addEventListener( "show" )

I see the error and it’s the same one

Hello ?

Didn’t you ask a similar question before?

Try an overlay, it might just work.

https://docs.coronalabs.com/api/library/composer/showOverlay.html

Please read and consider.

Thanks but like everyone said the problem was :

function scene:show(event) local sceneGroup = self.view composer.removeScene("restart") end

Did it work?

I did this :

restart.lua:

function scene:show(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("show started") elseif ( phase == "did" ) then print("show showing objects") composer.removeScene( "game" ) end Runtime:addEventListener("touch", touchScreen) end function scene:hide(event) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then print("hide started") display.remove(currentTimeText) display.remove(timerUpTimer) elseif ( phase == "did" ) then print("hide removing objects") composer.removeScene( "restart" ) end Runtime:removeEventListener("touch", touchScreen) end

I don’t see the error anymore with that code

That’s not how you call composer.gotoScene():

https://docs.coronalabs.com/api/library/composer/gotoScene.html

Do I have to put all of this ?

-- Later... local options = { effect = "fade", time = 800, params = { level="Level 1", score=currentScore } } composer.gotoScene( "results", options )

This is what I have and I’m getting the same error:

 local options = { effect = "fade", time = 400, } local function touchScreen( event ) if event.phase == "began" then composer.gotoScene( "game", options ) end end