Why the car nil?

Thanks. Sorry for taking your time reading my long code. I solve it. Thank you,

You can’t just post a load of code and ask why it doesn’t work… you have to try and do some checking yourself!

This is bad though: you have two references to Runtime:addEventListener(“enterFrame”, pathScroll)

I am sorry. I am new to this. andi got zero knowledge about this. I just learn all of this by google it. i am out of ideas. I have been staying all night long. Few days now. and still can solve this. i already ask other questions, still no answer. i do check it. But still clueless. The two references. What i understand i have two “path” object that’s why i need to put two references. Do correct me if i am wrong. But don’t tell me that like i am not working hard to solve this. Because i do. i am sorry. I’ve got no option left. Thank you.

simplify your code until it works… when coding change one thing and then test if it works… if it does then add another (single) line of code and test… if it doesn’t then fix it until it works

you get the point

hi i do what you said. And I know this is maybe still not the simplest. But can  you take a look ?why the car when in objectCollide/Collision it get this error. 

Attempt to index a nil value

but when the collision with coin it doesn’t give that error. why?? Can you please explain and point out the wrong in here? i am sorry for asking too much. but thank you so much.

---REQUIRESlocal composer = require( "composer" ) local scene = composer.newScene() composer.recycleOnSceneChange = true local widget = require( "widget" )&nbsp; local physics = require "physics" physics.start() local sendEnemyCar,createCoin,createCar,objectCollide,updateTimer,endGame local obj1 local obj2 local lanes = {} local laneID = 2 local lanes\_H = {} local enemyCars = {}&nbsp; local enemyCounter = 0 local Car={} local CarCounter = 0 local sendCarFrequency = 2500 local timeDisplay local tmr\_startGame,tmrToSendCars,tmrToSendCoin local coins = {} local coinsCounter = 0 local distance = 0 local score = 0 local scoreText local txt\_counter local scroll = 2 -- EFM local RightSide &nbsp; -- EFM local LeftSide -- EFM local rightLabel &nbsp;-- EFM local leftLabel &nbsp; -- EFM local path1 &nbsp; -- EFM local path2 &nbsp; -- EFM local ground local centerlane = (side/8) - 4 ---------------------- ---------------------- ---RUN COIN&nbsp; createCar = function () Car[CarCounter] = display.newImageRect("Cars/Kereta"..math.random(1,11)..".png", 150, 200) Car[CarCounter].x = lanes[math.random(1,#lanes)].x Car[CarCounter].y = -125 Car[CarCounter].id = "car" physics.addBody(Car[CarCounter], {bounce = 0, friction = 1, density = 0}) print (Car) Car[CarCounter].bodyType = "kinematic" transition.to(Car[CarCounter], {y=display.contentHeight+Car[CarCounter].height+20, time=math.random(2250,3000), onComplete=function(self) display.remove(self); end}) -- a transition that moves the enemy car towards the bottom of the screen. On completion, the enemy car object is removed from the game. CarCounter = CarCounter + 1 print (Car) end ---------------------- ---RUN COIN&nbsp; createCoin = function () coins[coinsCounter] = display.newImageRect("Point/coin1.png", 70, 70) coins[coinsCounter].x = lanes[math.random(1,#lanes)].x coins[coinsCounter].y = -125 coins[coinsCounter].id = "coin" physics.addBody(coins[coinsCounter], {bounce = 0, friction = 1, density = 0}) print (coins) coins[coinsCounter].bodyType = "kinematic" transition.to(coins[coinsCounter], {y=display.contentHeight+coins[coinsCounter].height+20, time=math.random(2250,3000), onComplete=function(self) display.remove(self); end}) -- a transition that moves the enemy car towards the bottom of the screen. On completion, the enemy car object is removed from the game. coinsCounter = coinsCounter + 1 print (coins) end ---------------------- ---COLLISION objectCollide = function (event) obj1 = event.object1 -- store the first object obj2 = event.object2 -- store the second object &nbsp; &nbsp; if(event.phase == "began") then -- when the enemy car collides into the player car, this if/then statement will be true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ("collision") &nbsp; &nbsp; print(obj1) &nbsp; &nbsp; print(coins) &nbsp; &nbsp; print(Car) &nbsp; &nbsp;if(obj1.id == "chick" and obj2.id == "car") then &nbsp; -- stop the game &nbsp; &nbsp;transition.pause() &nbsp; &nbsp;timer.cancel(tmrToSendCars) &nbsp; &nbsp;timer.cancel(tmrToSendCoin) &nbsp; &nbsp;physics.pause() &nbsp; -- remove event listeners from all lanes &nbsp; &nbsp; &nbsp; &nbsp;for i=1,#lanes do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", sendEnemyCar) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", createCoin) &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; for i=1,enemyCounter do &nbsp; &nbsp; &nbsp; if(enemyCars[i]) then&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.remove(enemyCars[i]) &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; &nbsp; for i=1,coinsCounter do &nbsp; &nbsp; &nbsp; if(coins[i]) then&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.remove(coins[i]) &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; &nbsp; --display.remove(coins[i]) &nbsp; &nbsp;display.remove(obj1) &nbsp; &nbsp;display.remove(obj2) &nbsp; &nbsp;timer.performWithDelay( 0, endGame ) &nbsp; &nbsp;end &nbsp; &nbsp;if(obj1.id == "chick" and obj2.id == "coin") then &nbsp; &nbsp;display.remove(obj2) &nbsp; &nbsp;score =score + 1 &nbsp; &nbsp;print ("Score: " .. score) scoreText.text = "Score: " .. score &nbsp; &nbsp;end &nbsp; &nbsp; end end ---------------------- updateTimer = function (event) &nbsp; &nbsp; distance = distance + 1 &nbsp; &nbsp; timeDisplay.text = distance &nbsp; &nbsp; if distance == 10 then &nbsp; &nbsp; &nbsp; &nbsp; print("Change background") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- stop the game &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--transition.pause() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--timer.cancel(tmrToSendCars) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--timer.cancel(tmrToSendCoin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--physics.pause() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--changeScene() &nbsp; &nbsp; &nbsp; end end ---END GAME endGame = function (event) --composer.setVariable( "finalScore", score ) --composer.setVariable( "finalScore1", score ) --distance=0 print("end leave game.lua") --Runtime:removeEventListener("enterFrame", pathScroll) Runtime:removeEventListener("enterFrame", pathScroll) RightSide:removeEventListener( "tap" ) LeftSide:removeEventListener( "tap" ) Runtime:removeEventListener( "collision", onCollision ) composer.gotoScene( "restart1", { time=800, effect="crossFade" } ) end ---------------------- ---CREATE&nbsp; -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. function scene:create( &nbsp;) local group = self.view local background = display.newGroup() -- EFM local road &nbsp; = display.newGroup() -- EFM local content = display.newGroup() -- EFM local interface &nbsp; = display.newGroup() -- EFM group:insert(background) group:insert(road) group:insert(content) group:insert(interface) ---TAP BACKGROUND --print(car) print(coins) LeftSide = display.newImageRect(background, "fillT.png", fullw/2, fullh ) -- EFM LeftSide.anchorX &nbsp;= 0 -- EFM LeftSide.x &nbsp; &nbsp; &nbsp; &nbsp;= left -- EFM LeftSide.y &nbsp; &nbsp; &nbsp; &nbsp;= centerY -- EFM function LeftSide.tap( self, event ) -- EFM print("Tapped Left Side") if laneID \> 1 then laneID = laneID - 1; transition.cancel(chick) local function onComplete() print( "At lane " .. laneID .. " to the left" ) end transition.to( chick, { x = lanes[laneID].x, time = 50, onComplete = onComplete } ) end return true end RightSide = display.newImageRect(background, "fillT.png", fullw/2, fullh ) -- EFM RightSide.anchorX &nbsp;= 1 -- EFM RightSide.x &nbsp; &nbsp; &nbsp; &nbsp;= right -- EFM RightSide.y &nbsp; &nbsp; &nbsp; &nbsp;= centerY -- EFM function RightSide.tap( self, event ) -- EFM print("Tapped Right Side") if laneID \< 3 then laneID = laneID + 1; transition.cancel(chick) local function onComplete() print( "At lane " .. laneID .. " to the right" ) end transition.to( chick, { x = lanes[laneID].x, time = 50, onComplete = onComplete } ) end return true end ---------------------- ---LABEL TAP rightLabel = display.newText( { text = "", x = 0, y = 0 , fontSize = 50 } ) interface:insert( rightLabel) rightLabel:setTextColor( 0 ) rightLabel.x = right - 50 rightLabel.y = centerY leftLabel = display.newText( { text = "", x = 0, y = 0, fontSize = 50 } ) interface:insert( leftLabel ) leftLabel:setTextColor( 0 ) leftLabel.x = left + 50 leftLabel.y = centerY ---------------------- ---PATHWAY (BACKGROUND) path1 = display.newImageRect( road, "road/theroad1.png", fullw, fullh ) path1.x = centerX path1.y = centerY path2 = display.newImageRect( road, "road/theroad2.png", fullw, fullh ) path2.x = centerX path2.y = centerY - fullh&nbsp; ---------------------- ---INVISIBLE GROUND ground = display.newImageRect(background, "fillT.png", 320, 70) ground.x = display.contentWidth\*0.5 ground.y = display.contentHeight physics.addBody(ground, "static" , { friction=0.5, bounce=0 }) ---------------------- --(centerX - (side + 125) ---LANES for i = 1, 3 do -- loop 3 times to create 3 lanes for our game &nbsp; &nbsp;laneimg = display.newImageRect( road, "fillT.png", side-40, fullh ) -- EFM &nbsp; &nbsp; lanes[i] = laneimg &nbsp; &nbsp; lanes[i].x = (side/4) + (i\*(side-centerlane)) --((i)\*(side))&nbsp; &nbsp; &nbsp; lanes[i].y = centerY &nbsp; &nbsp; lanes[i].id = i end ---------------------- ---LANES HORIZONTAL for r = 1, 10 do -- loop 3 times to create 3 lanes for our game &nbsp; &nbsp;laneHimg = display.newImageRect( road, "fillT.png", fullw, fullh/30 ) -- EFM &nbsp; &nbsp; lanes\_H[r] = laneHimg &nbsp; &nbsp; lanes\_H[r].x = centerX &nbsp; &nbsp; lanes\_H[r].y = r\*((bottom - centerX)/8) &nbsp; &nbsp; lanes\_H[r].id = r end ---------------------- ---CHICK chick = display.newImageRect( content, "Player/"..math.random(1,10)..".png",100,100) chick.x = lanes[2].x chick.y = lanes\_H[9].y chick.id = "chick" physics.addBody( chick, "dynamic" ,{ isSensor=true })&nbsp; ---------------------- &nbsp; &nbsp; timeDisplay = display.newText(content,distance,0,0,native.systemFrontBold,64) &nbsp; &nbsp; timeDisplay.x = centerX +200 &nbsp; &nbsp; timeDisplay.y = top + 50 scoreText = display.newText( content, "Score: " .. score, 400, 80, native.systemFont, 36 ) end ---------------------- ---PATHWAY SCROLL function pathScroll (self,event) &nbsp; &nbsp; path1.y = path1.y + scroll &nbsp; &nbsp; path2.y = path2.y + scroll &nbsp; &nbsp; if path1.y == fullh \* 2.5 then &nbsp; &nbsp; &nbsp; &nbsp; path1.y = fullh \* -.5 &nbsp; &nbsp; end &nbsp; &nbsp; if path2.y == fullh \* 2.5 then &nbsp; &nbsp; &nbsp; &nbsp; path2.y = fullh \* -.5 &nbsp; &nbsp; end end ---------------------- -- EFM HAS TWO PHASES \>\>\> "will" and "did" ---SHOW --that will show in scene function scene:show (event) if( event.phase == "will" ) then elseif( event.phase == "did" ) then local function startGame() ---FOR PATHWAY TO SCROLL path1.enterFrame = pathScroll path2.enterFrame = pathScroll Runtime:addEventListener("enterFrame", pathScroll) ---------------------- ---WHEN TAP TO RIGHT RightSide:addEventListener( "tap" ) rightLabel.text = "right" ---------------------- ---WHEN TAP TO LEFT LeftSide:addEventListener( "tap" ) leftLabel.text = "left" ---------------------- end &nbsp; &nbsp; timer.performWithDelay(1000, updateTimer, 0) &nbsp; &nbsp; tmr\_startGame = timer.performWithDelay(0, startGame, 1) -- allow the player to move shortly after the game has started &nbsp; &nbsp; tmrToSendCoin = timer.performWithDelay(1500, createCoin, 0) &nbsp; &nbsp; tmrToSendCar = timer.performWithDelay(1500, createCar, 0) tmrToSendCars = timer.performWithDelay(sendEnemyFrequency, sendEnemyCar, 0) Runtime:addEventListener( "collision", objectCollide ) -- create a global event listener to listen for any collision &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; end end ---------------------- ---HIDE&nbsp; --function scene:hide (event) --local sceneGroup = self.view -- if( event.phase == "will" ) then -- elseif( event.phase == "did" ) then -- end --end ---------------------- -- destroy() function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "enter", scene ) scene:addEventListener( "show", scene ) --scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

okayi do know why. because it cannot pass that endgame function. so how to pass it? can you at least give me clue. please.

Exact error messages and line numbers would be a good start. You’re expecting people to take 30+ minutes out of their day to read all your (uncommented) code, figure out how it works (without being able to run it), and then fix it. Someone might find some time eventually, but you might have to be patient.

For a start code like this will likely cause errors

&nbsp; &nbsp; &nbsp; &nbsp;for i=1,#lanes do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", sendEnemyCar) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", createCoin) &nbsp; &nbsp; &nbsp; &nbsp;end

you should walk it backwards instead

&nbsp; &nbsp; &nbsp; &nbsp;for i=#lanes, 1, -1 do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", sendEnemyCar) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", createCoin) &nbsp; &nbsp; &nbsp; &nbsp;end

I have to agree with the @nick_sherman. Dumping tons of code with no reference to the problem doesn’t help people solve your problem.

It’s really important to read this post:  https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

and follow it’s advice.

There is a console log window that opens with the simulator, copy and pasting the entire error stack trace is  helpful. Then let us know which line of code is the problem and maybe just post enough code to have the error line and a few lines above it. Maybe just the whole block or function will do to start with.

Rob

You can’t just post a load of code and ask why it doesn’t work… you have to try and do some checking yourself!

This is bad though: you have two references to Runtime:addEventListener(“enterFrame”, pathScroll)

I am sorry. I am new to this. andi got zero knowledge about this. I just learn all of this by google it. i am out of ideas. I have been staying all night long. Few days now. and still can solve this. i already ask other questions, still no answer. i do check it. But still clueless. The two references. What i understand i have two “path” object that’s why i need to put two references. Do correct me if i am wrong. But don’t tell me that like i am not working hard to solve this. Because i do. i am sorry. I’ve got no option left. Thank you.

simplify your code until it works… when coding change one thing and then test if it works… if it does then add another (single) line of code and test… if it doesn’t then fix it until it works

you get the point

hi i do what you said. And I know this is maybe still not the simplest. But can  you take a look ?why the car when in objectCollide/Collision it get this error. 

Attempt to index a nil value

but when the collision with coin it doesn’t give that error. why?? Can you please explain and point out the wrong in here? i am sorry for asking too much. but thank you so much.

---REQUIRESlocal composer = require( "composer" ) local scene = composer.newScene() composer.recycleOnSceneChange = true local widget = require( "widget" )&nbsp; local physics = require "physics" physics.start() local sendEnemyCar,createCoin,createCar,objectCollide,updateTimer,endGame local obj1 local obj2 local lanes = {} local laneID = 2 local lanes\_H = {} local enemyCars = {}&nbsp; local enemyCounter = 0 local Car={} local CarCounter = 0 local sendCarFrequency = 2500 local timeDisplay local tmr\_startGame,tmrToSendCars,tmrToSendCoin local coins = {} local coinsCounter = 0 local distance = 0 local score = 0 local scoreText local txt\_counter local scroll = 2 -- EFM local RightSide &nbsp; -- EFM local LeftSide -- EFM local rightLabel &nbsp;-- EFM local leftLabel &nbsp; -- EFM local path1 &nbsp; -- EFM local path2 &nbsp; -- EFM local ground local centerlane = (side/8) - 4 ---------------------- ---------------------- ---RUN COIN&nbsp; createCar = function () Car[CarCounter] = display.newImageRect("Cars/Kereta"..math.random(1,11)..".png", 150, 200) Car[CarCounter].x = lanes[math.random(1,#lanes)].x Car[CarCounter].y = -125 Car[CarCounter].id = "car" physics.addBody(Car[CarCounter], {bounce = 0, friction = 1, density = 0}) print (Car) Car[CarCounter].bodyType = "kinematic" transition.to(Car[CarCounter], {y=display.contentHeight+Car[CarCounter].height+20, time=math.random(2250,3000), onComplete=function(self) display.remove(self); end}) -- a transition that moves the enemy car towards the bottom of the screen. On completion, the enemy car object is removed from the game. CarCounter = CarCounter + 1 print (Car) end ---------------------- ---RUN COIN&nbsp; createCoin = function () coins[coinsCounter] = display.newImageRect("Point/coin1.png", 70, 70) coins[coinsCounter].x = lanes[math.random(1,#lanes)].x coins[coinsCounter].y = -125 coins[coinsCounter].id = "coin" physics.addBody(coins[coinsCounter], {bounce = 0, friction = 1, density = 0}) print (coins) coins[coinsCounter].bodyType = "kinematic" transition.to(coins[coinsCounter], {y=display.contentHeight+coins[coinsCounter].height+20, time=math.random(2250,3000), onComplete=function(self) display.remove(self); end}) -- a transition that moves the enemy car towards the bottom of the screen. On completion, the enemy car object is removed from the game. coinsCounter = coinsCounter + 1 print (coins) end ---------------------- ---COLLISION objectCollide = function (event) obj1 = event.object1 -- store the first object obj2 = event.object2 -- store the second object &nbsp; &nbsp; if(event.phase == "began") then -- when the enemy car collides into the player car, this if/then statement will be true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ("collision") &nbsp; &nbsp; print(obj1) &nbsp; &nbsp; print(coins) &nbsp; &nbsp; print(Car) &nbsp; &nbsp;if(obj1.id == "chick" and obj2.id == "car") then &nbsp; -- stop the game &nbsp; &nbsp;transition.pause() &nbsp; &nbsp;timer.cancel(tmrToSendCars) &nbsp; &nbsp;timer.cancel(tmrToSendCoin) &nbsp; &nbsp;physics.pause() &nbsp; -- remove event listeners from all lanes &nbsp; &nbsp; &nbsp; &nbsp;for i=1,#lanes do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", sendEnemyCar) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", createCoin) &nbsp; &nbsp; &nbsp; &nbsp;end &nbsp; &nbsp; for i=1,enemyCounter do &nbsp; &nbsp; &nbsp; if(enemyCars[i]) then&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.remove(enemyCars[i]) &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; &nbsp; for i=1,coinsCounter do &nbsp; &nbsp; &nbsp; if(coins[i]) then&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.remove(coins[i]) &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; &nbsp; --display.remove(coins[i]) &nbsp; &nbsp;display.remove(obj1) &nbsp; &nbsp;display.remove(obj2) &nbsp; &nbsp;timer.performWithDelay( 0, endGame ) &nbsp; &nbsp;end &nbsp; &nbsp;if(obj1.id == "chick" and obj2.id == "coin") then &nbsp; &nbsp;display.remove(obj2) &nbsp; &nbsp;score =score + 1 &nbsp; &nbsp;print ("Score: " .. score) scoreText.text = "Score: " .. score &nbsp; &nbsp;end &nbsp; &nbsp; end end ---------------------- updateTimer = function (event) &nbsp; &nbsp; distance = distance + 1 &nbsp; &nbsp; timeDisplay.text = distance &nbsp; &nbsp; if distance == 10 then &nbsp; &nbsp; &nbsp; &nbsp; print("Change background") &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- stop the game &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--transition.pause() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--timer.cancel(tmrToSendCars) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--timer.cancel(tmrToSendCoin) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--physics.pause() &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--changeScene() &nbsp; &nbsp; &nbsp; end end ---END GAME endGame = function (event) --composer.setVariable( "finalScore", score ) --composer.setVariable( "finalScore1", score ) --distance=0 print("end leave game.lua") --Runtime:removeEventListener("enterFrame", pathScroll) Runtime:removeEventListener("enterFrame", pathScroll) RightSide:removeEventListener( "tap" ) LeftSide:removeEventListener( "tap" ) Runtime:removeEventListener( "collision", onCollision ) composer.gotoScene( "restart1", { time=800, effect="crossFade" } ) end ---------------------- ---CREATE&nbsp; -- Initialize the scene here. -- Example: add display objects to "sceneGroup", add touch listeners, etc. function scene:create( &nbsp;) local group = self.view local background = display.newGroup() -- EFM local road &nbsp; = display.newGroup() -- EFM local content = display.newGroup() -- EFM local interface &nbsp; = display.newGroup() -- EFM group:insert(background) group:insert(road) group:insert(content) group:insert(interface) ---TAP BACKGROUND --print(car) print(coins) LeftSide = display.newImageRect(background, "fillT.png", fullw/2, fullh ) -- EFM LeftSide.anchorX &nbsp;= 0 -- EFM LeftSide.x &nbsp; &nbsp; &nbsp; &nbsp;= left -- EFM LeftSide.y &nbsp; &nbsp; &nbsp; &nbsp;= centerY -- EFM function LeftSide.tap( self, event ) -- EFM print("Tapped Left Side") if laneID \> 1 then laneID = laneID - 1; transition.cancel(chick) local function onComplete() print( "At lane " .. laneID .. " to the left" ) end transition.to( chick, { x = lanes[laneID].x, time = 50, onComplete = onComplete } ) end return true end RightSide = display.newImageRect(background, "fillT.png", fullw/2, fullh ) -- EFM RightSide.anchorX &nbsp;= 1 -- EFM RightSide.x &nbsp; &nbsp; &nbsp; &nbsp;= right -- EFM RightSide.y &nbsp; &nbsp; &nbsp; &nbsp;= centerY -- EFM function RightSide.tap( self, event ) -- EFM print("Tapped Right Side") if laneID \< 3 then laneID = laneID + 1; transition.cancel(chick) local function onComplete() print( "At lane " .. laneID .. " to the right" ) end transition.to( chick, { x = lanes[laneID].x, time = 50, onComplete = onComplete } ) end return true end ---------------------- ---LABEL TAP rightLabel = display.newText( { text = "", x = 0, y = 0 , fontSize = 50 } ) interface:insert( rightLabel) rightLabel:setTextColor( 0 ) rightLabel.x = right - 50 rightLabel.y = centerY leftLabel = display.newText( { text = "", x = 0, y = 0, fontSize = 50 } ) interface:insert( leftLabel ) leftLabel:setTextColor( 0 ) leftLabel.x = left + 50 leftLabel.y = centerY ---------------------- ---PATHWAY (BACKGROUND) path1 = display.newImageRect( road, "road/theroad1.png", fullw, fullh ) path1.x = centerX path1.y = centerY path2 = display.newImageRect( road, "road/theroad2.png", fullw, fullh ) path2.x = centerX path2.y = centerY - fullh&nbsp; ---------------------- ---INVISIBLE GROUND ground = display.newImageRect(background, "fillT.png", 320, 70) ground.x = display.contentWidth\*0.5 ground.y = display.contentHeight physics.addBody(ground, "static" , { friction=0.5, bounce=0 }) ---------------------- --(centerX - (side + 125) ---LANES for i = 1, 3 do -- loop 3 times to create 3 lanes for our game &nbsp; &nbsp;laneimg = display.newImageRect( road, "fillT.png", side-40, fullh ) -- EFM &nbsp; &nbsp; lanes[i] = laneimg &nbsp; &nbsp; lanes[i].x = (side/4) + (i\*(side-centerlane)) --((i)\*(side))&nbsp; &nbsp; &nbsp; lanes[i].y = centerY &nbsp; &nbsp; lanes[i].id = i end ---------------------- ---LANES HORIZONTAL for r = 1, 10 do -- loop 3 times to create 3 lanes for our game &nbsp; &nbsp;laneHimg = display.newImageRect( road, "fillT.png", fullw, fullh/30 ) -- EFM &nbsp; &nbsp; lanes\_H[r] = laneHimg &nbsp; &nbsp; lanes\_H[r].x = centerX &nbsp; &nbsp; lanes\_H[r].y = r\*((bottom - centerX)/8) &nbsp; &nbsp; lanes\_H[r].id = r end ---------------------- ---CHICK chick = display.newImageRect( content, "Player/"..math.random(1,10)..".png",100,100) chick.x = lanes[2].x chick.y = lanes\_H[9].y chick.id = "chick" physics.addBody( chick, "dynamic" ,{ isSensor=true })&nbsp; ---------------------- &nbsp; &nbsp; timeDisplay = display.newText(content,distance,0,0,native.systemFrontBold,64) &nbsp; &nbsp; timeDisplay.x = centerX +200 &nbsp; &nbsp; timeDisplay.y = top + 50 scoreText = display.newText( content, "Score: " .. score, 400, 80, native.systemFont, 36 ) end ---------------------- ---PATHWAY SCROLL function pathScroll (self,event) &nbsp; &nbsp; path1.y = path1.y + scroll &nbsp; &nbsp; path2.y = path2.y + scroll &nbsp; &nbsp; if path1.y == fullh \* 2.5 then &nbsp; &nbsp; &nbsp; &nbsp; path1.y = fullh \* -.5 &nbsp; &nbsp; end &nbsp; &nbsp; if path2.y == fullh \* 2.5 then &nbsp; &nbsp; &nbsp; &nbsp; path2.y = fullh \* -.5 &nbsp; &nbsp; end end ---------------------- -- EFM HAS TWO PHASES \>\>\> "will" and "did" ---SHOW --that will show in scene function scene:show (event) if( event.phase == "will" ) then elseif( event.phase == "did" ) then local function startGame() ---FOR PATHWAY TO SCROLL path1.enterFrame = pathScroll path2.enterFrame = pathScroll Runtime:addEventListener("enterFrame", pathScroll) ---------------------- ---WHEN TAP TO RIGHT RightSide:addEventListener( "tap" ) rightLabel.text = "right" ---------------------- ---WHEN TAP TO LEFT LeftSide:addEventListener( "tap" ) leftLabel.text = "left" ---------------------- end &nbsp; &nbsp; timer.performWithDelay(1000, updateTimer, 0) &nbsp; &nbsp; tmr\_startGame = timer.performWithDelay(0, startGame, 1) -- allow the player to move shortly after the game has started &nbsp; &nbsp; tmrToSendCoin = timer.performWithDelay(1500, createCoin, 0) &nbsp; &nbsp; tmrToSendCar = timer.performWithDelay(1500, createCar, 0) tmrToSendCars = timer.performWithDelay(sendEnemyFrequency, sendEnemyCar, 0) Runtime:addEventListener( "collision", objectCollide ) -- create a global event listener to listen for any collision &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; end end ---------------------- ---HIDE&nbsp; --function scene:hide (event) --local sceneGroup = self.view -- if( event.phase == "will" ) then -- elseif( event.phase == "did" ) then -- end --end ---------------------- -- destroy() function scene:destroy( event ) local sceneGroup = self.view end scene:addEventListener( "create", scene ) scene:addEventListener( "enter", scene ) scene:addEventListener( "show", scene ) --scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) return scene

okayi do know why. because it cannot pass that endgame function. so how to pass it? can you at least give me clue. please.

Exact error messages and line numbers would be a good start. You’re expecting people to take 30+ minutes out of their day to read all your (uncommented) code, figure out how it works (without being able to run it), and then fix it. Someone might find some time eventually, but you might have to be patient.

For a start code like this will likely cause errors

&nbsp; &nbsp; &nbsp; &nbsp;for i=1,#lanes do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", sendEnemyCar) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", createCoin) &nbsp; &nbsp; &nbsp; &nbsp;end

you should walk it backwards instead

&nbsp; &nbsp; &nbsp; &nbsp;for i=#lanes, 1, -1 do &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", sendEnemyCar) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;lanes[i]:removeEventListener("touch", createCoin) &nbsp; &nbsp; &nbsp; &nbsp;end

I have to agree with the @nick_sherman. Dumping tons of code with no reference to the problem doesn’t help people solve your problem.

It’s really important to read this post:  https://forums.coronalabs.com/topic/55780-ask-a-better-question-get-a-better-answer/

and follow it’s advice.

There is a console log window that opens with the simulator, copy and pasting the entire error stack trace is  helpful. Then let us know which line of code is the problem and maybe just post enough code to have the error line and a few lines above it. Maybe just the whole block or function will do to start with.

Rob