I cant seem to unerstand this !

I have an error that I don’t understand just like most of them .

Error:

Windows simulator build date: May 27 2015 @ 18:15:50

Copyright © 2009-2015  C o r o n a   L a b s   I n c .
        Version: 3.0.0
        Build: 2015.2646
Platform: SM-G900S / x64 / 6.2 / Intel® HD Graphics / 4.0.0 - Build 10.18.10.3
408 / 2015.2646
Loading project from:   c:\users\true\documents\corona projects\bouncy blocks
Project sandbox folder: C:\Users\True\AppData\Roaming\Corona Labs\Corona Simulat
or\Sandbox\bouncy blocks-C116AB3B868BE13E671AF11DFB4D395F\Documents
WARNING: display.setStatusBarMode() not supported in the simulator for SM-G900S
device
ERROR: c:\users\true\documents\corona projects\bouncy blocks\level1.lua:5: physi
cs.start() must be called before physics.setGravity()
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:120: attempt to
 index global ‘background’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:120: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:113>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        (tail call): ?
        ?: in function <?:498>
        ?: in function <?:221>

What does this error mean and how do I fix it .

level1.lua:

local composer = require( "composer" ) local scene = composer.newScene() local physics = require( "physics" ) physics.setGravity(0, 40) local myObject local wall local wall2 local wall3 local block local block2 local mAbs = math.abs local mRand = math.random local mDeg = math.deg local mRad = math.rad local mCos = math.cos local mSin = math.sin local mAcos = math.acos local mAsin = math.asin local mSqrt = math.sqrt local mCeil = math.ceil local mFloor = math.floor local mAtan2 = math.atan2 local mPi = math.pi local getInfo = system.getInfo local getTimer = system.getTimer local strMatch = string.match local strFormat = string.format local pairs = pairs function scene:create( event ) local sceneGroup = self.view physics.start() physics.pause() local background = display.newImage( "background.png" ) sceneGroup:insert( background ) local ground = display.newImage( "ground.png" ) sceneGroup:insert( ground ) ground.isGround = true physics.addBody( ground, "static" , { friction=0.5, bounce=0.1 } ) myObject = display.newRect( 0, 0, 100, 30 ) sceneGroup:insert( myObject ) myObject.isMyObject = true myObject:setFillColor( 0 ) physics.addBody( myObject, "kinematic" , { myObject, friction=0.5, bounce=2 } ) function myObject:touch( event ) if( event.phase == "moved" ) then self.x = event.x self.y = event.y end return true end myObject:addEventListener( "touch", myObject ) wall = display.newImageRect( "wall.png", 600, 300 ) sceneGroup:insert( wall ) wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=0.5 } ) wall2 = display.newImageRect( "wall2.png", 500, 300 ) sceneGroup:insert( wall2 ) wall.rotation = 90 physics.addBody( wall2, "static" , { wall2, friction=0.5, bounce=0.5 } ) wall3 = display.newImageRect( "wall3.png", 600, 300 ) sceneGroup:insert( wall3 ) wall3.rotation = 90 physics.addBody( wall3, "static" , { wall3, friction=0.5, bounce=0.5 } ) block = display.newImage( "block.png" ) sceneGroup:insert( block ) block.isBlock = true block.rotation = 8 physics.addBody( block, "dynamic" , { block, friction=0.5, bounce=0.5 } ) block.collision = onCollision block:addEventListener( "collision" ) block2 = display.newImage( "block2.png" ) sceneGroup:insert( block2 ) block2.isBlock = true block2.rotation = 8 physics.addBody( block2, "dynamic" , { block2, friction=0.5, bounce=0.5 } ) block2.collision = onCollision block2:addEventListener( "collision" ) end onCollision = function( self, event ) local other = event.other if( event.phase == "began" and self.isBlock and other.isGround ) then timer.performWithDelay( 30, function() composer.gotoScene ( "restart", "fade", 0 ) end ) self:removeEventListener( "collision" ) end return true end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then background.x = 10 background.y = 308 ground.x = 145 ground.y = 480 myObject.x = 145 myObject.y = 400 wall.x = -150 wall.y = 250 wall2.x = 210 wall2.y = -194 wall3.x = 470 wall3.y = 250 block.x = 200 block2.x = 100 elseif ( phase == "did" ) then physics.start() -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene

Thank you and bless you .

Looks like you didn’t start physics before setting gravity.
Try this:

local physics = require( "physics" ) physics.start() physics.setGravity(0, 40)

Note: The trick to reading error messages is to read them backwards.
 
Start on the last error message, then go to the one before it, then the one before that, etc.
 
At each error, take a look at the specified file and line. If you don’t see anything obvious, keep going till you find the cause.  Generally it is the first line, in the sequence, but sometimes not.
 
Note: Finding errors in scene files can be especially daunting, because composer will sometimes lose its mind when there is a syntax error.
 
Trick: If you run into a wacky error message in a scene, try requiring it instead of loading it.  This may help you find the error:
Ex: instead of this:

composer.gotoScene( "bobsLounge" ) -- crazy errors ensue, but can't figure them out

Try this:

--composer.gotoScene( "bobsLounge" ) require( "bobsLounge" ) -- This won't do anything, but the error may just pop out in a nice message

There is also a scope error.  

Runtime error c:\users\true\documents\corona projects\bouncy blocks\level1.lua:120: attempt to &nbsp;index global 'background' (a nil value)

You have created the “background” object as a local variable inside the scene:create() function, this means that it cannot be accessed from outside the function. When you try to set background.x in scene:show(), the function does not know that this object exists.  

What you need to do is make it an object that is accessible to all functions in that file:

local composer = require( "composer" ) local scene = composer.newScene() local physics = require( "physics" ) physics.setGravity(0, 40) --create a forward reference for the background object local background function scene:create( event ) --remove the word 'local' from here --and assign the image to the background variable created above. background = display.newImage( "background.png" ) sceneGroup:insert( background ) end function scene:show( event ) if ( phase == "will" ) then background.x = 10 background.y = 308 end

Looks like you didn’t start physics before setting gravity.
Try this:

local physics = require( "physics" ) physics.start() physics.setGravity(0, 40)

Note: The trick to reading error messages is to read them backwards.
 
Start on the last error message, then go to the one before it, then the one before that, etc.
 
At each error, take a look at the specified file and line. If you don’t see anything obvious, keep going till you find the cause.  Generally it is the first line, in the sequence, but sometimes not.
 
Note: Finding errors in scene files can be especially daunting, because composer will sometimes lose its mind when there is a syntax error.
 
Trick: If you run into a wacky error message in a scene, try requiring it instead of loading it.  This may help you find the error:
Ex: instead of this:

composer.gotoScene( "bobsLounge" ) -- crazy errors ensue, but can't figure them out

Try this:

--composer.gotoScene( "bobsLounge" ) require( "bobsLounge" ) -- This won't do anything, but the error may just pop out in a nice message

There is also a scope error.  

Runtime error c:\users\true\documents\corona projects\bouncy blocks\level1.lua:120: attempt to &nbsp;index global 'background' (a nil value)

You have created the “background” object as a local variable inside the scene:create() function, this means that it cannot be accessed from outside the function. When you try to set background.x in scene:show(), the function does not know that this object exists.  

What you need to do is make it an object that is accessible to all functions in that file:

local composer = require( "composer" ) local scene = composer.newScene() local physics = require( "physics" ) physics.setGravity(0, 40) --create a forward reference for the background object local background function scene:create( event ) --remove the word 'local' from here --and assign the image to the background variable created above. background = display.newImage( "background.png" ) sceneGroup:insert( background ) end function scene:show( event ) if ( phase == "will" ) then background.x = 10 background.y = 308 end