I used ":" !

I have had a problem for a long time . This problem was that my objects don’t reposition to there original place when I go to level1.lua from restart.lua . I was told some corrections y Rob Miracle that didn’t work at the time because of another mistake I made . It is fixed now .But I have a new 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:35: disp
lay.newImage() bad argument #1: filename or image sheet expected, but got nil
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:36: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
        [C]: in function ‘insert’
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:36: in
function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:31>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

Level1.lua:

local composer = require( "composer" ) local scene = composer.newScene() local physics = require( "physics" ) physics.start() physics.setGravity(0, 40) physics.setDrawMode("hybrid") 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 local background = display.newImage( group, "background.png" ) sceneGroup:insert( background ) local ground = display.newImage( group, "ground.png" ) sceneGroup:insert( ground ) ground.isGround = true physics.addBody( ground, "static" , { friction=0.5, bounce=0.1 } ) local myObject = display.newRect( group, 0, 0, 100, 30 ) sceneGroup:insert( myObject ) 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 ) local wall = display.newImageRect( group, "wall.png", 600, 300 ) sceneGroup:insert( wall ) wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=0.5 } ) local wall2 = display.newImageRect( group, "wall2.png", 500, 300 ) sceneGroup:insert( wall2 ) wall.rotation = 90 physics.addBody( wall2, "static" , { wall2, friction=0.5, bounce=0.5 } ) local wall3 = display.newImageRect( group, "wall3.png", 600, 300 ) sceneGroup:insert( wall3 ) wall3.rotation = 90 physics.addBody( group, wall3, "static" , { wall3, friction=0.5, bounce=0.5 } ) local block = display.newImage( group, "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" ) local block2 = display.newImage( group, "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 -- 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

Why is this error happening and how do I fix it ?

Thank you.

This one is easy:

local sceneGroup = self.view &nbsp; local background = display.newImage( group, "background.png" ) sceneGroup:insert( background )

What is the variable name of the scene’s group defined in the first line of code?

What variable are  you trying to add the image to in the 2nd line?   group does not equal sceneGroup.  Therefore group is nil and the image load fails setting background to nil. The in the 3rd line you get an error because you can’t insert a nil into a group.

Now a couple of things to think about. If you create images like you’re doing where the first parameter is the group, then you don’t need the 3rd line because you added it to the group.  There are two ways to fix this:

local sceneGroup = self.view &nbsp; local background = display.newImage( "background.png" ) sceneGroup:insert( background )

or

local sceneGroup = self.view &nbsp; local background = display.newImage( sceneGroup, "background.png" )

I prefer the first way, not the second, but they end up doing the same thing.

In Corona SDK an object can only be in one group at a time. So if you did have a display.newGroup() named “group”, the 3rd line would move it from “group” to “sceneGroup” any way.

Rob

 

Got rid of one error now another comes up which is a one I think I solved myself I just need to see if im right .Error:

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:38: disp
lay.newImage() bad argument #1: filename or image sheet expected, but got nil
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
        [C]: in function ‘insert’
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: in
function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:31>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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:38: disp
lay.newImage() bad argument #1: filename or image sheet expected, but got nil
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
        [C]: in function ‘insert’
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: in
function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:31>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:70: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
        [C]: in function ‘addBody’
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:70: in
function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:31>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:104>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:114: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:114: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:103>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:104>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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
Runtime error
error loading module ‘level1’ from file ‘c:\users\true\documents\corona projects
\bouncy blocks\level1.lua’:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:9: ‘=’
expected near ‘local’
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
error loading module ‘level1’ from file ‘c:\users\true\documents\corona projects
\bouncy blocks\level1.lua’:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:9: ‘=’
expected near ‘local’
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:104>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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:7: physi
cs.setDrawMode() parameter must be one of ‘normal’, ‘hybrid’ or ‘debug’
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:105>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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:7: physi
cs.setDrawMode() parameter must be one of ‘normal’, ‘hybrid’ or ‘debug’
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:105>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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:7: physi
cs.setDrawMode() parameter must be one of ‘normal’, ‘hybrid’ or ‘debug’
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:105>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

Does this mean I have to put local at the beginning o line 116 as well as the other ones . If not what is this error trying to say ?

New level1.lua:

local composer = require( "composer" ) local scene = composer.newScene() local physics = require( "physics" ) physics.start() physics.setGravity(0, 40) physics.setDrawMode( hybrid ) 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 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 } ) local 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 ) local wall = display.newImageRect( "wall.png", 600, 300 ) sceneGroup:insert( wall ) wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=0.5 } ) local wall2 = display.newImageRect( "wall2.png", 500, 300 ) sceneGroup:insert( wall2 ) wall.rotation = 90 physics.addBody( wall2, "static" , { wall2, friction=0.5, bounce=0.5 } ) local wall3 = display.newImageRect( "wall3.png", 600, 300 ) sceneGroup:insert( wall3 ) wall3.rotation = 90 physics.addBody( wall3, "static" , { wall3, friction=0.5, bounce=0.5 } ) local 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" ) local 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 -- 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.

Regardless of anything else, don’t forget to forward declare functions and variables

This is a global in your code which will bite you later:

onCollision = function( self, event )

Did you delete your post named “How to name a sceneGroup?”  and then re-post your code here with a new variant of the problem?

If so please don’t do that.

I put a lot of time into answering your post, and if you deleted it, you just wasted my time.  

At the top add:

local myObject

Then take the local off inside createScene.

Rob

This one is easy:

local sceneGroup = self.view &nbsp; local background = display.newImage( group, "background.png" ) sceneGroup:insert( background )

What is the variable name of the scene’s group defined in the first line of code?

What variable are  you trying to add the image to in the 2nd line?   group does not equal sceneGroup.  Therefore group is nil and the image load fails setting background to nil. The in the 3rd line you get an error because you can’t insert a nil into a group.

Now a couple of things to think about. If you create images like you’re doing where the first parameter is the group, then you don’t need the 3rd line because you added it to the group.  There are two ways to fix this:

local sceneGroup = self.view &nbsp; local background = display.newImage( "background.png" ) sceneGroup:insert( background )

or

local sceneGroup = self.view &nbsp; local background = display.newImage( sceneGroup, "background.png" )

I prefer the first way, not the second, but they end up doing the same thing.

In Corona SDK an object can only be in one group at a time. So if you did have a display.newGroup() named “group”, the 3rd line would move it from “group” to “sceneGroup” any way.

Rob

 

Got rid of one error now another comes up which is a one I think I solved myself I just need to see if im right .Error:

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:38: disp
lay.newImage() bad argument #1: filename or image sheet expected, but got nil
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
        [C]: in function ‘insert’
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: in
function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:31>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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:38: disp
lay.newImage() bad argument #1: filename or image sheet expected, but got nil
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
        [C]: in function ‘insert’
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:39: in
function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:31>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:70: ERROR: tabl
e expected. If this is a function call, you might have used ‘.’ instead of ‘:’
stack traceback:
        [C]: in function ‘addBody’
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:70: in
function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:31>
        ?: in function ‘dispatchEvent’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:104>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:114: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:114: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:103>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:104>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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
Runtime error
error loading module ‘level1’ from file ‘c:\users\true\documents\corona projects
\bouncy blocks\level1.lua’:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:9: ‘=’
expected near ‘local’
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
error loading module ‘level1’ from file ‘c:\users\true\documents\corona projects
\bouncy blocks\level1.lua’:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:9: ‘=’
expected near ‘local’
stack traceback:
        [C]: in function ‘error’
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\menu.lua:25: in fu
nction <c:\users\true\documents\corona projects\bouncy blocks\menu.lua:23>
        ?: in function <?:221>

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
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:115: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:104>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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:7: physi
cs.setDrawMode() parameter must be one of ‘normal’, ‘hybrid’ or ‘debug’
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:105>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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:7: physi
cs.setDrawMode() parameter must be one of ‘normal’, ‘hybrid’ or ‘debug’
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:105>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

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:7: physi
cs.setDrawMode() parameter must be one of ‘normal’, ‘hybrid’ or ‘debug’
Runtime error
c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: attempt to
 index global ‘myObject’ (a nil value)
stack traceback:
        c:\users\true\documents\corona projects\bouncy blocks\level1.lua:116: in
 function <c:\users\true\documents\corona projects\bouncy blocks\level1.lua:105>

        ?: in function ‘dispatchEvent’
        ?: in function ‘_nextTransition’
        ?: in function <?:1492>
        ?: in function ‘gotoScene’
        c:\users\true\documents\corona projects\bouncy blocks\restart.lua:23: in
 function <c:\users\true\documents\corona projects\bouncy blocks\restart.lua:19>

        ?: in function <?:221>

Does this mean I have to put local at the beginning o line 116 as well as the other ones . If not what is this error trying to say ?

New level1.lua:

local composer = require( "composer" ) local scene = composer.newScene() local physics = require( "physics" ) physics.start() physics.setGravity(0, 40) physics.setDrawMode( hybrid ) 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 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 } ) local 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 ) local wall = display.newImageRect( "wall.png", 600, 300 ) sceneGroup:insert( wall ) wall.rotation = 90 physics.addBody( wall, "static" , { wall, friction=0.5, bounce=0.5 } ) local wall2 = display.newImageRect( "wall2.png", 500, 300 ) sceneGroup:insert( wall2 ) wall.rotation = 90 physics.addBody( wall2, "static" , { wall2, friction=0.5, bounce=0.5 } ) local wall3 = display.newImageRect( "wall3.png", 600, 300 ) sceneGroup:insert( wall3 ) wall3.rotation = 90 physics.addBody( wall3, "static" , { wall3, friction=0.5, bounce=0.5 } ) local 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" ) local 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 -- 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.

Regardless of anything else, don’t forget to forward declare functions and variables

This is a global in your code which will bite you later:

onCollision = function( self, event )

Did you delete your post named “How to name a sceneGroup?”  and then re-post your code here with a new variant of the problem?

If so please don’t do that.

I put a lot of time into answering your post, and if you deleted it, you just wasted my time.  

At the top add:

local myObject

Then take the local off inside createScene.

Rob