Hi, this error keeps on appearing after my scene changes from game to score scene . I know i posted a lot of code on here, but the error is between lines 110 and 130!!! If anyone can help, I would be extremely grateful!!
If your going to criticize my code, please keep in mind I’m new to corona sdk.
local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------- -- Code outside of the scene event functions below will only be executed ONCE unless -- the scene is removed entirely (not recycled) via "composer.removeScene()" -- ----------------------------------------------------------------------------------- local physics = require( "physics" ) physics.start() --physics.setDrawMode( "hybrid" ) physics.setGravity( 0,-.07 ) -- -------------------- local lives = 1 local score = 0 local died = false local ship local gameLoopTimer local scoreText -- set up display groups local backGroup local mainGroup local uiGroup sheetInfo = require("explosion") -- init the image sheet explosion = graphics.newImageSheet( "explosion.png", sheetInfo:getSheet() ) sequenceData = { -- set up anmiation { name="explosion", -- name of the animation (used with setSequence) explosion=myImageSheet, -- the image sheet start=sheetInfo:getFrameIndex("1"), -- name of the first frame count=10, -- number of frames time=2250, -- speed loopCount=1, -- repeat direction ="forward", }, } explosion = display.newSprite( explosion, sequenceData ) explosion.myName = "explosion" explosion.x = x explosion.y = y explosion:setSequence("explosion") explosion:play() explosion.isVisible = false ---------------------------------------------------------------------------------------- -- Drone Placement local droneInfo = require "drone" local droneSheet = graphics.newImageSheet( "drone.png", droneInfo:getSheet() ) local droneSeqData = { {name = "droe", frames = {1,2,3}, time=150, loopCount=0, loopDirection = "forward"}, } local drone = display.newSprite( droneSheet, droneSeqData ) drone.x = display.contentWidth-570 drone.y = display.contentHeight-200 drone:setSequence( "idle" ) drone:play() drone.speed = math.random(6, 12) drone.initY = drone.y drone.amp = math.random(20,100) drone.angle = math.random(20,80) physics.addBody( drone,"static", {density=.1, bounce=0.1, }) local droneInfo = require "drone" local droneSheet = graphics.newImageSheet( "drone.png", droneInfo:getSheet() ) local droneSeqData = { {name = "droe2", frames = {1,2,3}, time=150, loopCount=0, loopDirection = "forward"}, } local drone2 = display.newSprite( droneSheet, droneSeqData ) drone2.x = display.contentWidth-370 drone2.y = display.contentHeight-200 drone2:setSequence( "idle" ) drone2:play() drone2.speed = math.random(6, 12) drone2.initY = drone2.y drone2.amp = math.random(20,100) drone2.angle = math.random(20,80) physics.addBody( drone2 ,"static", {density=.1, bounce=0.1, }) ---------------------------------------------------------------------------------------- -- helicopter Working function moveHelicopters(self,event) if helicopter.x \<- 350 then helicopter.x = 550 helicopter.speed = math.random(6, 18) helicopter.amp = math.random(60,80) helicopter.angle = math.random(20,80) else helicopter.x = helicopter.x - helicopter.speed helicopter.angle = helicopter.angle + .05 helicopter.y = helicopter.amp\*math.sin(helicopter.angle)+helicopter.initY end end ---------------------------------------------------------------------------------------- local function updateText() scoreText.text = "Score: ".. score end function moveDrones(self,event) if drone.x \<- 180 then drone.x = 571 drone.speed = math.random(6, 18) drone.amp = math.random(80,120) drone.angle = math.random(60,80) else drone.x = drone.x - drone.speed drone.angle = drone.angle + .04 drone.y = drone.amp\*math.sin(drone.angle)+drone.initY end end drone.enterFrame = moveDrones Runtime:addEventListener("enterFrame", drone) -- ship Movements function activateShips(self, event) self:applyForce( 0, -02.1, ship.x, ship.y) end function touchScreen(event) if event.phase == "began" then ship.enterFrame = activateShips Runtime:addEventListener("enterFrame", ship) end if event.phase == "ended" then Runtime:removeEventListener("enterFrame", ship ) end end ---------------------------------------------------------------------------------------- -- explosion effect function explode() explosion.x = ship.x explosion.y = ship.y explosion.isVisible = true explosion:play() ship.isVisible = false end ---------------------------------------------------------------------------------------- -- Drones Working function moveDrones(self,event) if drone2.x \<- 180 then drone2.x = 571 drone2.speed = math.random(6, 18) drone2.amp = math.random(60,120) drone2.angle = math.random(60,80) else drone2.x = drone2.x - drone2.speed drone2.angle = drone2.angle + .03 drone2.y = drone2.amp\*math.sin(drone2.angle)+drone2.initY score = score + 1 scoreText.text = "Score: " .. score end end drone2.enterFrame = moveDrones Runtime:addEventListener("enterFrame", drone2) ---------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------- -- ------------------------------------------------------------------------------------- -- ----------------------------------------------------------------------------------- -- 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 physics.pause() -- Temporarily pause the physics engine -- Set up display groups backGroup = display.newGroup() -- Display group for the background image sceneGroup:insert( backGroup ) -- Insert into the scene's view group mainGroup = display.newGroup() -- Display group for the ship, asteroids, lasers, etc. sceneGroup:insert( mainGroup ) -- Insert into the scene's view group uiGroup = display.newGroup() -- Display group for UI objects like the score sceneGroup:insert( uiGroup ) -- -------------------------------------------------------------------------------------------------- local background = display.newImageRect( backGroup, "background.png", 740, 415 ) background.x = display.contentCenterX background.y = display.contentCenterY -- helicopter placement helicopterInfo = require "helicopter" helicopterSeqData = { {name = "heli", frames = {1,2,3}, time=150, loopCount=0, loopDirection = "forward"}, } helicopterSheet = graphics.newImageSheet( "helicopter.png", helicopterInfo:getSheet() ) helicopter = display.newSprite( mainGroup ,helicopterSheet, helicopterSeqData ) physics.addBody( helicopter,"static",{density=.1, bounce=0.1, friction=.2, radius=30 } ) helicopter.x = display.contentWidth-570 helicopter.y = display.contentHeight-200 helicopter:setSequence( "idle" ) helicopter:play() helicopter.speed = math.random(8, 18) helicopter.initY = helicopter.y helicopter.amp = math.random(20,100) helicopter.angle = math.random(40,80) -- -------------------------------------------------------------------------------------------------- local city1 = display.newImageRect(backGroup, "city1.png", 720, 580 ) city1.x = 0 city1.y = display.contentHeight-280 -- -------------------------------------------------------------------------------------------------- local city2 = display.newImageRect(backGroup, "city1.png", 720, 580 ) city2.x = 780 city2.y = display.contentHeight-280 local top = display.newImageRect( mainGroup, "top.png", 130, 15 ) top.x = 60 top.y = -10 physics.addBody( top,"static", {} ) local bottom = display.newImageRect( mainGroup, "top.png", 130, 15 ) bottom.x = 60 bottom.y = 435 physics.addBody( bottom,"static", {} ) local bottom = display.newImageRect( mainGroup, "top.png", 130, 15 ) bottom.x = 60 bottom.y = 435 physics.addBody( bottom,"static", {} ) local gravityButtom = display.newImageRect(mainGroup, "GravityButton.png", 140, 140 ) gravityButtom.x = 400 gravityButtom.y = 350 -- -------------------------------------------------------------------------------------------------- local function endGame() composer.setVariable( "finalScore", score ) composer.gotoScene( "highscore", { time=800, effect="crossFade" } ) end -- collisiion function function onCollision(event) if event.phase == "began" then if ship.collided == false then ship.collided = true timer.performWithDelay( 2000, endGame ) ship.bodyType = "static" explode() else end end end Runtime:addEventListener("collision", onCollision) -- -------------------------------------------------------------------------------------------------- city1.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city1) city2.enterFrame = scrollCity Runtime:addEventListener("enterFrame", city2) -- ---------------------------------------------------------------------------------------- ship = display.newImageRect( mainGroup, "alienship.png", 60, 45 ) ship.myName = "ship" ship.x = -400 ship.y = 195 ship.collided = false physics.addBody( ship, "static", { radius=20, bounce= 0}) function alienReady() ship.bodyType = ("dynamic") ship.gravityScale = -1085 end transition.to(ship,{time=1000, x=10, onComplete=alienReady}) gravityButtom:addEventListener( "touch" , touchScreen) scoreText = display.newText(uiGroup, "Score: " .. score, 400, 80, native.systemFont, 36) 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 physics.start() Runtime:addEventListener("collision", onCollision) helicopter.enterFrame = moveHelicopters Runtime:addEventListener("enterFrame", moveHelicopters) 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) elseif ( phase == "did" ) then -- Code here runs immediately after the scene goes entirely off screen physics.start() Runtime:addEventListener("collision", onCollision) physics.pause() composer.removeScene( "game" ) end end -- destroy() function scene:destroy( event ) local sceneGroup = self.view -- Code here runs prior to the removal of scene's view local function endGame() composer.setVariable( "finalScore", score ) composer.gotoScene( "highscore", { time=800, effect="crossFade" } ) composer.removeScene( "game" ) end end -- ----------------------------------------------------------------------------------- -- Scene event function listeners -- ----------------------------------------------------------------------------------- scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ----------------------------------------------------------------------------------- return scene