What does this error mean?

I am not getting this error.The game is running successfully for some time then when collision takes place between; the scene is changed to end scene( as I want). But as soon as the end scene is launched the simulator shows this error. Attempt to index local “round1” (a nil value) .I have attached a screen shot of this.I have tried a lot but I am not getting any solution.

----------------------------------------------------------------------------------------- -- -- level1.lua -- ----------------------------------------------------------------------------------------- local composer = require( "composer" ) local scene = composer.newScene() local physics = require "physics" local speedTimer local gameLoopTimer -------------------------------------------- -- fucntion to destroy to scene. local function destroyScene() composer.gotoScene( "end", { time=800, effect="crossFade" } ) composer.removeScene("game") end -- function to destroy scene and game. local function endGame() timer.cancel(gameLoopTimer) --Stop spawning balls, game over timer.performWithDelay(200,function() destroyScene() end) end -- score (in format of seconds) local secondsLeft = 0 local clockText = display.newText(secondsLeft, display.contentCenterX , 50, native.systemFontBold, 60) clockText:setFillColor( 0.8, 2.2, 1.3 ) local function updateTime( event ) secondsLeft = secondsLeft + 10 local seconds = secondsLeft % 100000 local timeDisplay = string.format( "%02d", seconds ) clockText.text = timeDisplay end time = timer.performWithDelay( 100, updateTime, secondsLeft ) -- put medals in game. local medal10 = display.newImageRect( "10.png", 30, 30) medal10.x, medal10.y = display.contentCenterX, display.contentCenterY-5000 local medal9 = display.newImageRect("9.png", 30, 30) medal9.x, medal9.y = display.contentCenterX, display.contentCenterY-5000 local medal8 = display.newImageRect( "8.png", 30, 30) medal8.x, medal8.y = display.contentCenterX, display.contentCenterY-5000 local medal7 = display.newImageRect("7.png", 30, 30) medal7.x, medal7.y = display.contentCenterX, display.contentCenterY-5000 local medal6 = display.newImageRect( "6.png", 30, 30) medal6.x, medal6.y = display.contentCenterX, display.contentCenterY-5000 local medal5 = display.newImageRect("5.png", 30, 30) medal5.x, medal5.y = display.contentCenterX, display.contentCenterY-5000 local medal4 = display.newImageRect( "4.png", 30, 30) medal4.x, medal4.y = display.contentCenterX, display.contentCenterY-5000 local medal3 = display.newImageRect("3.png", 30, 30) medal3.x, medal3.y = display.contentCenterX, display.contentCenterY-5000 local medal2 = display.newImageRect( "2.png", 30, 30) medal2.x, medal2.y = display.contentCenterX, display.contentCenterY-5000 local medal1 = display.newImageRect("1.png", 30, 30) medal1.x, medal1.y = display.contentCenterX, display.contentCenterY-5000 local function medal10D () medal10.x = display.contentCenterX-140 medal10.y = display.contentCenterY-250 end local myClosure10 = function () return medal10D () end timer.performWithDelay( 10000, myClosure10, 1) local function medal9D () medal9.x = display.contentCenterX-110 medal9.y = display.contentCenterY-250 end local myClosure9 = function () return medal9D () end timer.performWithDelay( 24000, myClosure9, 1) local function medal8D () medal8.x = display.contentCenterX-80 medal8.y = display.contentCenterY-250 end local myClosure8 = function () return medal8D () end timer.performWithDelay( 42000, myClosure8, 1) local function medal7D () medal7.x = display.contentCenterX-50 medal7.y = display.contentCenterY-250 end local myClosure7 = function () return medal7D () end timer.performWithDelay( 64000, myClosure7, 1) local function medal6D () medal6.x = display.contentCenterX-20 medal6.y = display.contentCenterY-250 end local myClosure6 = function () return medal6D () end timer.performWithDelay( 90000, myClosure6, 1) local function medal1D () medal1.x = display.contentCenterX+130 medal1.y = display.contentCenterY-250 end local myClosure1 = function () return medal1D () end timer.performWithDelay( 284000, myClosure1, 1) local function medal5D () medal5.x = display.contentCenterX+10 medal5.y = display.contentCenterY-250 end local myClosure2 = function () return medal5D () end timer.performWithDelay( 120000, myClosure2, 1) local function medal4D () medal4.x = display.contentCenterX+40 medal4.y = display.contentCenterY-250 end local myClosure4 = function () return medal4D () end timer.performWithDelay( 154000, myClosure4, 1) local function medal3D () medal3.x = display.contentCenterX+70 medal3.y = display.contentCenterY-250 end local myClosure3 = function () return medal3D () end timer.performWithDelay( 192000, myClosure3, 1) local function medal2D () medal2.x = display.contentCenterX+100 medal2.y = display.contentCenterY-250 end local myClosure2 = function () return medal2D () end timer.performWithDelay( 234000, myClosure2, 1) -- collion detection starts. local function onCollisionA( self, event ) local collideObject = event.other if ( collideObject.surfaceType == "magic" ) then self:removeSelf() elseif ( collideObject.surfaceType == "magicm") then self:removeSelf() endGame() if time then timer.cancel(time) end transition.moveBy( clockText, { x=-5, y=130, time=2000 } ) transition.moveBy( medal10, { x=60, y=270, time=2000 } ) transition.moveBy( medal9, { x=60, y=270, time=2000 } ) transition.moveBy( medal8, { x=60, y=270, time=2000 } ) transition.moveBy( medal7, { x=60, y=270, time=2000 } ) transition.moveBy( medal6, { x=60, y=270, time=2000 } ) transition.moveBy( medal5, { x=60, y=270, time=2000 } ) transition.moveBy( medal4, { x=-90, y=300, time=2000 } ) transition.moveBy( medal3, { x=-90, y=300, time=2000 } ) transition.moveBy( medal2, { x=-90, y=300, time=2000 } ) transition.moveBy( medal1, { x=-90, y=300, time=2000 } ) textremoval = timer.performWithDelay( 10000, function() display.remove(clockText) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal10) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal9) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal8) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal7) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal6) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal5) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal4) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal3) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal2) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal1) end, 1) end end -------- local function onCollisionB( self, event ) local collideObject = event.other if ( collideObject.surfaceType == "magicm" ) then self:removeSelf() elseif ( collideObject.surfaceType == "magic") then self:removeSelf() endGame() if time then timer.cancel(time) end transition.moveBy( clockText, { x=-5, y=130, time=2000 } ) transition.moveBy( medal10, { x=60, y=270, time=2000 } ) transition.moveBy( medal9, { x=60, y=270, time=2000 } ) transition.moveBy( medal8, { x=60, y=270, time=2000 } ) transition.moveBy( medal7, { x=60, y=270, time=2000 } ) transition.moveBy( medal6, { x=60, y=270, time=2000 } ) transition.moveBy( medal5, { x=60, y=270, time=2000 } ) transition.moveBy( medal4, { x=-90, y=300, time=2000 } ) transition.moveBy( medal3, { x=-90, y=300, time=2000 } ) transition.moveBy( medal2, { x=-90, y=300, time=2000 } ) transition.moveBy( medal1, { x=-90, y=300, time=2000 } ) textremoval = timer.performWithDelay( 10000, function() display.remove(clockText) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal10) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal9) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal8) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal7) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal6) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal5) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal4) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal3) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal2) end, 1) medalreemoval = timer.performWithDelay( 10000, function () display.remove( medal1) end, 1) end end --collision detection ends. --function to drag platform local function dragplatfrom2( event ) local platform2 = event.target local phase = event.phase if ( "began" == phase ) then -- Set touch focus on the zypa2 display.currentStage:setFocus( platform2 ) -- Store initial offset position platform2.touchOffsetX = event.x - platform2.x platform2.isFocus = true elseif ( "moved" == phase and platform2.isFocus) then -- Move the zypa2 to the new touch position platform2.x = event.x - platform2.touchOffsetX elseif ( "ended" == phase or "cancelled" == phase ) then -- Release touch focus on the zypa2 display.currentStage:setFocus( nil ) platform2.isFocus = nil end return true -- Prevents touch propagation to underlying objects end ------------- local function dragplatfrom( event ) local platform = event.target local phase = event.phase if ( "began" == phase ) then display.currentStage:setFocus( platform ) platform.isFocus = true platform.touchOffsetX = event.x - platform.x elseif ( "moved" == phase and platform.isFocus) then platform.x = event.x - platform.touchOffsetX elseif ( "ended" == phase or "cancelled" == phase ) then display.currentStage:setFocus( nil ) platform.isFocus = nil end return true -- Prevents touch propagation to underlying objects end ---------------- local function dragplatfrom3( event ) local platform3 = event.target local phase = event.phase if ( "began" == phase ) then display.currentStage:setFocus( platform3 ) platform3.isFocus = true platform3.touchOffsetX = event.x - platform3.x elseif ( "moved" == phase and platform3.isFocus) then platform3.x = event.x - platform3.touchOffsetX elseif ( "ended" == phase or "cancelled" == phase ) then display.currentStage:setFocus( nil ) platform3.isFocus = nil end return true -- Prevents touch propagation to underlying objects end --function to drag platform ends. -- put zypas in game. local function drawBalls() local rand = math.random(6) if (rand \< 5) then local round1 = display.newImageRect( scene.view, "1.jpg", 90, 90) round1.x, round1.y = 50, 50 round1.collision = onCollisionA round1.collision = onCollisionB round1:addEventListener("collision") physics.addBody( round1, "dynamic", { bounce=0.0, radius=20 } ) local round2 = display.newImageRect( scene.view,"2.jpg", 90, 90 ) round2.x, round2.y = 160, 50--Put our balls into the scene view so they are cleaned up on reload round2.collision = onCollisionA round2.collision = onCollisionB round2:addEventListener("collision") physics.addBody( round2, "dynamic", { bounce=0.0, radius=20 } ) local round3 = display.newImageRect( scene.view,"3.jpg", 90, 90 ) round3.x, round3.y = 270, 50 --Put our balls into the scene view so they are cleaned up on reload round3.collision = onCollisionA round3.collision = onCollisionB round3:addEventListener("collision") physics.addBody( round3, "dynamic", { bounce=0.0, radius=20 } ) end end local function gameLoop() drawBalls() --Draw balls every 3s end function scene:create( event ) local sceneGroup = self.view physics.start() physics.setGravity(0,1) local background = display.newImageRect( sceneGroup,"space5.jpg", display.actualContentWidth, display.actualContentHeight ) background.x = display.contentCenterX background.y = display.contentCenterY local platform = display.newImageRect( sceneGroup,"plat1.jpg", 100, 50 ) platform.surfaceType = "magic" platform.x, platform.y = display.contentCenterX, display.contentCenterY+200 physics.addBody( platform, "static", { bounce=0.0, friction=0.3 } ) platform:addEventListener( "touch", dragplatfrom ) local platform2 = display.newImageRect( sceneGroup,"plat2.jpg", 100, 50 ) platform2.surfaceType = "magicm" platform2.x, platform2.y = display.contentCenterX, display.contentCenterY+150 physics.addBody( platform2, "static", { bounce=0.0, friction=0.3 } ) speedTimer = timer.performWithDelay( 10000, function() physics.setGravity(0,3) end, 1) platform2:addEventListener( "touch", dragplatfrom2 ) local platform3 = display.newImageRect( sceneGroup,"plat3.jpg", 100, 50 ) platform3.surfaceType = "magic" platform3.x, platform3.y = display.contentCenterX, display.contentCenterY+250 physics.addBody( platform3, "static", { bounce=0.0, friction=0.3 } ) platform3:addEventListener( "touch", dragplatfrom3 ) drawBalls() gameLoopTimer = timer.performWithDelay( 3000, gameLoop, 0 ) local function performGameloop() gameLoopTimer = timer.performWithDelay( 1000, gameLoop, 0 ) end local myClosure = function() return performGameloop () end timer.performWithDelay( 15000, myClosure, 0) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if phase == "will" then -- Called when the scene is still off screen and is about to move on screen elseif phase == "did" then -- Called when the scene is now on screen -- -- INSERT code here to make the scene come alive -- e.g. start timers, begin animation, play audio, etc. physics.start() end end function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if event.phase == "will" then physics.pause() elseif phase == "did" then -- Called when the scene is now off screen end end function scene:destroy( event ) -- Called prior to the removal of scene's "view" (sceneGroup) -- INSERT code here to cleanup the scene -- e.g. remove display objects, remove touch listeners, save state, etc. local sceneGroup = self.view if speedTimer then timer.cancel(speedTimer) end if physics then package.loaded[physics] = nil end physics = nil end --------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) ----------------------------------------------------------------------------------------- return scene

unrealted but arn’t you overwriting the variable so onCollisionA won’t fire?

round1.collision = onCollisionA
round1.collision = onCollisionB

because 1.jpg could not be found as an image.

Thanks. It helped.

I got the error.

Make sure 1.jpg is in the root folder with this file, also it might help if you change the name of the image to round1, round2, etc. You have a 1.png and a 1.jpg.

unrealted but arn’t you overwriting the variable so onCollisionA won’t fire?

round1.collision = onCollisionA
round1.collision = onCollisionB

because 1.jpg could not be found as an image.

Thanks. It helped.

I got the error.

Make sure 1.jpg is in the root folder with this file, also it might help if you change the name of the image to round1, round2, etc. You have a 1.png and a 1.jpg.