heres my entire game code the only runtime listener i have is for collision, im thinking it has to do with where im inserting the objects into the group but when i try to insert it to the group in another part of the code it gives me a syntax error
here is my full code for my game minus the start and restart screen which is just some event listeners for tapping the screen
im still relatively new at this so im hoping everythings right
and i havent added any comments in so im sorry if its confusing, im still trying to get into the habit of commenting
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 backgroundGroup local gameGroup local UIGroup -- ----------------------------------------------------------------------------------- -- Scene event functions -- ----------------------------------------------------------------------------------- local gravity = .5 local hitPoints = 3 local timerNum = 0 local loop = 0 local hits = 0 local randomSpawn = math.random(3) local blueTime local greenTime local redTime = 1 local scoreNumber = 0 local background local platform local ball local scoreBoard local score local scoreVisual local life1 local life2 local life3 local grayDot local redDot local blueDot local greenDot local damageSquare local function endGame() composer.gotoScene("restart") end -- 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 background = display.newImageRect("background.png",320, 668 ) background.x = display.contentCenterX background.y = display.contentCenterY background:toBack() backgroundGroup = display.newGroup() backgroundGroup = display.newGroup() backgroundGroup:insert(background) sceneGroup:insert(backgroundGroup) gameGroup = display.newGroup() sceneGroup:insert( gameGroup ) UIGroup = display.newGroup() sceneGroup:insert(UIGroup) platform = display.newImageRect("Platform.png", 360, 35) platform.name = "platform" platform.x = display.contentCenterX platform.y = 505 platform.yScale = display.contentScaleY + 1 gameGroup:insert(platform) ball = display.newImageRect("square.png", 50, 50) ball.name = "ball" ball.x = display.contentCenterX ball.y = display.contentCenterY sceneGroup:insert(ball) scoreBoard = display.newImageRect("scoreboard.png", 330, 35 ) scoreBoard.x = display.contentCenterX scoreBoard.y = -30 scoreBoard:toFront() UIGroup:insert(scoreBoard) score = display.newText( "Score: ", display.contentWidth - 270, display.contentHeight - 510, native.systemFontBold, 20 ) score:setFillColor(255, 255, 255) UIGroup:insert(score) scoreVisual = display.newText( scoreNumber, 270, display.contentHeight - 510, {width = 128}, native.systemFontBold, 20, {align = "right"}) UIGroup:insert(scoreVisual) life1 = display.newImageRect("square.png", 20, 20) life1.x = 15 life1.y = 0 UIGroup:insert(life1) life2 = display.newImageRect("square.png", 20, 20) life2.x = 35 life2.y = 0 UIGroup:insert(life2) life3 = display.newImageRect("square.png", 20, 20) life3.x = 55 life3.y = 0 UIGroup:insert(life3) 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) physics.start() physics.setGravity (0, 25) physics.addBody(platform, "static", {bounce = .2, friction = 1}) physics.addBody(ball, "dynamic", {bounce = 0, friction = 1}) elseif ( phase == "did" ) then -- Code here runs when the scene is entirely on screen local function onTouch(event) local ball = event.target local phase = event.phase if ( "began" == phase ) then -- Set touch focus on the ball display.currentStage:setFocus( ball ) -- Store initial offset position ball.touchOffsetX = event.x - ball.x elseif ( "moved" == phase ) then -- Move the ball to the new touch position ball.x = event.x - ball.touchOffsetX if ball.x \< 24 then ball.x = 24 display.currentStage:setFocus(nil) elseif event.x \> 296 then ball.x = 296 display.currentStage:setFocus(nil) end elseif ( "ended" == phase or "cancelled" == phase ) then -- Release touch focus on the ball display.currentStage:setFocus( nil ) end return true end local function onCollision(event) local phase = event.phase if phase == "began" then local obj1 = event.object1 local obj2 = event.object2 if (obj1.name == "ball" and obj2.name == "grayDot")or (obj1.name == "grayDot" and obj2.name == "ball") then display.remove(obj2) scoreNumber = scoreNumber + 250 scoreVisual.text = scoreNumber elseif (obj1.name == "platform" and obj2.name == "grayDot")or (obj1.name == "grayDot" and obj2.name == "platform") then display.remove(obj2) end if (obj1.name == "ball" and obj2.name == "redDot")or (obj1.name == "redDot" and obj2.name == "ball") then display.remove(obj2) scoreNumber = scoreNumber + 500 scoreVisual.text = scoreNumber elseif (obj1.name == "platform" and obj2.name == "redDot")or (obj1.name == "redDot" and obj2.name == "platform") then display.remove(obj2) end if (obj1.name == "ball" and obj2.name == "blueDot")or (obj1.name == "blueDot" and obj2.name == "ball") then display.remove(obj2) scoreNumber = scoreNumber + 750 scoreVisual.text = scoreNumber elseif (obj1.name == "platform" and obj2.name == "blueDot")or (obj1.name == "blueDot" and obj2.name == "platform") then display.remove(obj2) end if (obj1.name == "ball" and obj2.name == "greenDot")or (obj1.name == "greenDot" and obj2.name == "ball") then display.remove(obj2) scoreNumber = scoreNumber + 250 scoreVisual.text = scoreNumber elseif (obj1.name == "platform" and obj2.name == "greenDot")or (obj1.name == "greenDot" and obj2.name == "platform") then display.remove(obj2) end if (obj1.name == "ball" and obj2.name == "damage")or (obj1.name == "damage" and obj2.name == "ball") then display.remove(obj2) hits = hits + 1 print(hits) if hits == 1 then display.remove(life3) elseif hits == 2 then display.remove(life2) elseif hits == 3 then display.remove(life1) endGame() physics.pause() end elseif (obj1.name == "platform" and obj2.name == "damage")or (obj1.name == "damage" and obj2.name == "platform") then display.remove(obj2) end elseif phase == "ended" then end return true end function spawnRed() local function redTime() redDot = display.newImageRect("RedDot.png", 30, 30) redDot.x = math.random(20, 300) redDot.y = -60 physics.addBody(redDot, "dynamic", {bounce = 0}) redDot.gravityScale = .7 redDot.name = "redDot" gameGroup:insert(redDot) end timer.performWithDelay(5000, redTime, 0) end function damagePoint() damageSquare = display.newImageRect("whiteSquare.png", 20, 20) damageSquare.x = math.random(20, 300) damageSquare.y = -60 damageSquare.name = "damage" physics.addBody(damageSquare, "dynamic", {bounce = 0}) damageSquare.gravityScale = 1.5 gameGroup:insert(damageSquare) end function spawnBlue() local function blueTime() blueDot = display.newImageRect("blueDot.png", 30, 30) blueDot.x = math.random(20, 300) blueDot.y = -60 physics.addBody(blueDot, "dynamic", {bounce = 0}) blueDot.gravityScale = 2 blueDot.name = "blueDot" gameGroup:insert(blueDot) end timer.performWithDelay(8000, blueTime, 0) end function spawnGreen() local function greenTime() greenDot = display.newImageRect("greenDot.png", 30, 30) greenDot.x = math.random(20, 300) greenDot.y = -60 physics.addBody(greenDot, "dynamic", {bounce = 0}) greenDot.gravityScale = 3 greenDot.name = "greenDot" gameGroup:insert(greenDot) end timer.performWithDelay(15000, greenTime, 0) end function spawnGray() grayDot = display.newImageRect("gray\_dot.png", 30, 30) grayDot.x = math.random(20, 300) grayDot.y = -60 physics.addBody(grayDot, "dynamic", {bounce = 0}) grayDot.gravityScale = .5 grayDot.name = "grayDot" gameGroup:insert(grayDot) end Runtime:addEventListener("collision", onCollision) ball:addEventListener("touch", onTouch) end if loop == 0 then timer.performWithDelay(1000, spawnGray, 0) timer.performWithDelay(6000, spawnRed) timer.performWithDelay(12000, spawnBlue) timer.performWithDelay(18000, spawnGreen) timer.performWithDelay(6000, damagePoint, 0) 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 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