hey guys
when my game overs, it takes me to gameOver scene…but it gives me this error
14:34:12.052 ERROR: Runtime error 14:34:12.052 ERROR: nil key supplied for property lookup. 14:34:12.052 stack traceback: 14:34:12.052 [C]: ? 14:34:12.052 ?: in function 'removeEventListener' 14:34:12.052 ?: in function 'removeEventListener' 14:34:12.052 ?: in function 'removeEventListener' 14:34:12.052 C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:335: in function \<C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:328\> 14:34:12.052 ?: in function 'dispatchEvent' 14:34:12.052 ?: in function '\_saveSceneAndHide' 14:34:12.052 ?: in function 'gotoScene' 14:34:12.052 C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:250: in function \<C:\Users\admin\Documents\Corona Projects\Game\freePlay\freePlay.lua:250\> 14:34:12.052 (tail call): ? 14:34:12.052 ?: in function \<?:504\> 14:34:12.052 ?: in function \<?:169\>
my code of my game is this :
local composer = require( "composer" ) local scene = composer.newScene() local physics = require "physics" physics.start() physics.setGravity(0,13) physics.setDrawMode("normal") user = loadsave.loadTable("user.json") -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- -- time local timeCounter = 0 -- enemies local virus = {} -- enemies table local enemyTravelSpeed = 2000 -- enemy travel speed across the screen local enemySendSpeed = 100 local enemyCounter = 0 local enemyIncrementSpeed = 5 local enemyMaxSendSpeed = 10 -- score properties user.score = 0 local scoreText -- other properties local ball, ground, leftWall, rightWall local ballRadius = 30 -- if isScoringUp is set to true, then, when enemy collides with the ground, score up, else don't score up. local isScoringUp = true local onGameOver -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- -- create() function scene:create( event ) local sceneGroup = self.view -- Code here runs when the scene is first created but has not yet appeared on screen local backgroundImage = display.newImageRect(sceneGroup,"freePlay/images/Background image.png",800,1400) backgroundImage.x = centerX backgroundImage.y = centerY backgroundImage.width = screenWidth backgroundImage.height = screenHeight scoreText = display.newText(sceneGroup, "Score:0",0,0,\_font,40) scoreText.anchorX = 1 scoreText.x = screenRight - scoreText.width \* 0.1 scoreText.y = screenTop + scoreText.height local function dragMe(event) local self=event.target if event.phase == "began" then display.getCurrentStage():setFocus(self,event.id) --create a touch joint so that gravity doesn't pull the object down self.tempJoint = physics.newJoint( "touch", self, event.x, event.y ) self.isFocus = true self.isFixedRotation = true --stop the object from rotating while being dragged elseif self.isFocus then if event.phase == "moved" then self.tempJoint:setTarget( event.x, event.y ) elseif event.phase == "ended" or event.phase == "cancelled" then display.getCurrentStage():setFocus(self,nil) self.isFixedRotation = false self.isFocus = false self.tempJoint:removeSelf() end end return true end -- to be created local function onPauseTouch( event ) -- body end -- sending enemies local function sendEnemies() -- body -- timeCounter : keeps track of the time in the game, starts at 0 -- enemySendSpeed : will tell us how often to send the enemies, starts at 100 -- enemyCounter : keeps track of the number of enemies on the screen, starts at 0 -- enemyIncrementSpeed : how much to increase the enemy speed, starts at 10 -- enemyMaxSendSpeed : limit the send speed to 400, starts at 400 timeCounter = timeCounter + 1 if ((timeCounter%enemySendSpeed == 0)) then enemyCounter = enemyCounter + 1 enemySendSpeed = enemySendSpeed - enemyIncrementSpeed if enemySendSpeed \>= 50 then enemyIncrementSpeed = 5 end if enemySendSpeed \<= 50 then enemyIncrementSpeed = 2 end if (enemySendSpeed \<= enemyMaxSendSpeed) then enemySendSpeed = enemyMaxSendSpeed end virus[enemyCounter] = display.newImageRect(sceneGroup ,"freePlay/images/virus.png",100,100) virus[enemyCounter].x = math.random(screenLeft + screenWidth \* 0.1, screenRight - screenWidth \* 0.1) virus[enemyCounter].y = screenTop - virus[enemyCounter].height virus[enemyCounter].name = "enemy" physics.addBody(virus[enemyCounter],"dynamic") virus[enemyCounter].isFixedRotation = false transition.to(virus[enemyCounter], {y = screenBottom - virus[enemyCounter].height \* 0.5, time =enemyTravelSpeed, onComplete = function(self) if self ~= nil then display.remove(self); end end }) end end --scoring up local function scoreUp( event ) -- body user.score = user.score + 100 scoreText.text = "Score:".. user.score scoreText.anchorX = 1 scoreText.x = screenRight - scoreText.width \* 0.1 loadsave.saveTable(score,"user.json") end -- onCollision local function onCollision(event) if (event.phase == "began") then if (event.object1.name == "ball" and event.object2.name == "enemy") then print("Game Over1") if event.target.object1 ~= nil then --display.remove(event.target.object1) timer.performWithDelay(10,showBanners(event.object1, event.object2),1) --onGameOver(event.object1, event.object2) end elseif (event.object2.name == "ball" and event.object1.name == "enemy")then print("Game Over2") if event.object2 ~= nil then --display.remove(event.object2) showBanners(event.object2, event.object1) --onGameOver(event.object2, event.object1) end elseif (event.object1.name == "enemy" and event.object2.name == "ground")then if isScoringUp == true then if event.object1 ~= nil then print("Score Up") display.remove(event.object1) scoreUp() end elseif isScoringUp == false then if event.object1 ~= nil then print("No score Up") display.remove(event.object1) scoreUp() end end elseif (event.object1.name == "ground" and event.object2.name == "enemy")then if isScoringUp == true then if event.object2 ~= nil then print("Score Up") display.remove(event.object2) scoreUp() end elseif isScoringUp == false then if event.object2 ~= nil then print("No score Up") display.remove(event.object2) scoreUp() end end end end end local function onGameOver() print("enemies cleared") --ball:removeEventListener("touch",dragMe) end function showBanners(obj1,obj2 ) -- body print("Hey") audio.play(shockSound) transition.pause() physics.pause() Runtime:removeEventListener("enterFrame",sendEnemies) --up banner banner1 = display.newImage(sceneGroup,"freePlay/images/collision/upBanner.png") banner1.x = obj1.x + 50 banner1.y = obj1.y - 180 banner1:scale(0,0) -- down banner banner2 = display.newImage(sceneGroup,"freePlay/images/collision/downBanner.png") banner2.x = obj1.x banner2.y = obj1.y + 180 banner2:scale(0,0) -- right banner banner3 = display.newImage(sceneGroup,"freePlay/images/collision/rightBanner.png") banner3.x = obj1.x + 180 banner3.y = obj1.y banner3:scale(0,0) -- left banner banner4 = display.newImage(sceneGroup,"freePlay/images/collision/leftBanner.png") banner4.x = obj1.x - 180 banner4.y = obj1.y banner4:scale(0,0) -- increasing the scale of ball and banners transition.to(ball,{xScale = 2, yScale = 2, time = 500, onComplete = function () Runtime:removeEventListener("collision",onCollision)end }) transition.to(banner1,{xScale = 1 , yScale = 1, time =200}) transition.to(banner2,{xScale = 1 , yScale = 1, time =200}) transition.to(banner3,{xScale = 1 , yScale = 1, time =200}) transition.to(banner4,{xScale = 1 , yScale = 1, time =200}) -- moving banners off screens timer.performWithDelay(2000, function() transition.to(banner1,{x = screenRight + 200, y = obj1.y - 250, time = 500, alpha = 0, onComplete = function () display.remove(self)end }) transition.to(banner2,{x = screenLeft - 200, y = obj1.y + 250, time = 500 , alpha = 0,onComplete = function () display.remove(self)end }) transition.to(banner3,{x = obj1.x + 250, y = screenBottom + 200, time = 500, alpha =0 ,onComplete = function () display.remove(self)end}) transition.to(banner4,{x = obj1.x - 200, y = screenTop - 250, time = 500, alpha = 0,onComplete = function () display.remove(self)end}) end ) -- removing enemies timer.performWithDelay(3000, function() physics.start() for i = 1, #virus do if virus[i] ~= nil then transition.to(virus[i],{alpha = 0, time = 500, onComplete = function() display.remove(virus[i]); composer.gotoScene("freePlay.gameOver","crossFade",1000) end })--error in this line end end end ,1) end if user.isRedEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/red-white-ball.png",60,60) elseif user.isYellowEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/yellow-white-ball.png",60,60) elseif user.isPurpleEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/purple-white-ball.png",60,60) elseif user.isOrangeEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/orange-white-ball.png",60,60) elseif user.isBlueEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/blue-white-ball.png",60,60) elseif user.isGreenEnabled == true then ball = display.newImageRect(sceneGroup,"upImages/ball/green-white-ball.png",60,60) end ball.x = centerX ball.y = centerY ball.name = "ball" physics.addBody(ball,"dynamic",{radius = ballRadius, bounce = 0.5}) ball:addEventListener("touch",dragMe) ground = display.newRect (sceneGroup,0,0,screenWidth,20) ground.x = centerX ground.y = screenBottom + ground.height \* 0.5 ground:setFillColor(1,1,1) ground.name = "ground" physics.addBody(ground,"static") leftWall = display.newRect (sceneGroup,0,0,20,screenHeight) leftWall.x = screenLeft - leftWall.width \* 0.5 leftWall.y = centerY leftWall:setFillColor(1,1,1) physics.addBody(leftWall,"static") rightWall = display.newRect (sceneGroup,0,0,20,screenHeight) rightWall.x = screenRight + rightWall.width \* 0.5 rightWall.y = centerY rightWall:setFillColor(1,1,1) physics.addBody(rightWall,"static") Runtime:addEventListener("enterFrame" ,sendEnemies) Runtime:addEventListener("collision", onCollision) end -- show() function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is still off screen (but is about to come on screen) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen end end -- hide() function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Code here runs when the scene is on screen (but is about to go off screen) ball:removeEventListener("touch",dragMe) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene
error was in composer.gotoScene line
please help

