Corona Runtime Error: '(' expected near local

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- -- Your code here --hide status bar display.setStatusBar( display.HiddenStatusBar ) --Physics local physics = require("physics") physics.start() physics.setGravity(0,0) -- Random Seed math.randomseed(os.time()) --Spritesheet local sheetOptions = { frames = { { -- 1) asteroid 1 x = 0, y = 0, width = 102, height = 85 }, { -- 2) asteroid 2 x = 0, y = 85, width = 90, height = 83 }, { -- 3) asteroid 3 x = 0, y = 168, width = 100, height = 97 }, { -- 4) ship x = 0, y = 265, width = 98, height = 79 }, { -- 5) laser x = 98, y = 265, width = 14, height = 40 }, }, } local objectSheet = graphics.newImageSheet("gameObjects.png", sheetOptions) --Stats local lives = 3 local score = 0 local died = false local asteroidsTable={} local ship local gameLoopTimer local livesText local scoreText --Display Groups local backGroup = display.newGroup() local mainGroup = display.newGroup() local uiGroup = display.newGroup() --Background local background = display.newImageRect(backGroup,"background.png", 800, 1400) background.x = display.contentCenterX background.y = display.contentCenterY --Object Loading ship = display.newImageRect( mainGroup, objectSheet, 4, 98, 79 ) ship.x = display.contentCenterX ship.y = display.contentHeight -100 physics.addBody(ship,{radius=30, isSensor=true}) ship.myName="ship" --Lives and Sccore livesText = display.newText(uiGroup, "Lives: "..lives,200, 80, native.systemFont, 36) scoreText = display.newText(uiGroup, "Score: "..score, 400, 80, native.systemFont, 36) local function updateText() livesText.text = "Lives: "..lives scoreText.text = "Score: "..score end --Asteroid Creation local function createAsteroid local newAsteroid = display.newImageRect( mainGroup, objectSheet, 1, 102, 85 ) table.insert( asteroidsTable, newAsteroid ) physics.addBody( newAsteroid, "dynamic", { radius=40, bounce=0.8 } ) newAsteroid.myName = "asteroid" local whereFrom = math.random(3) if(whereFrom==1) then --From the Left newAsteroid.x = -60 newAsteroid.y = math.random(500) newAsteroid:setLinearVelocity(math.random(40,200),math.random(20,60)) elseif ( whereFrom == 2 ) then -- From the top newAsteroid.x = math.random( display.contentWidth ) newAsteroid.y = -60 newAsteroid:setLinearVelocity( math.random( -40,40 ), math.random( 40,120 ) ) elseif ( whereFrom == 3 ) then -- From the right newAsteroid.x = display.contentWidth + 60 newAsteroid.y = math.random( 500 ) newAsteroid:setLinearVelocity( math.random( -120,-40 ), math.random( 20,60 ) ) end end

Hi!

I have been following the guide on how to make a game using Corona. I am on lesson 3. For reference here is the link to the tutorial: https://docs.coronalabs.com/guide/programming/03/index.html

I am on the movement section and I wanted to test out whether everything was fine with my code and a runtime error occured. Here is what it says in the log:

10:30:31.482  Copyright © 2009-2017  C o r o n a   L a b s   I n c .

10:30:31.482   Version: 3.0.0

10:30:31.482   Build: 2017.3068

10:30:31.497  Platform: GT-I9300 / x64 / 10.0 / Intel® HD Graphics 5500 / 4.4.0 - Build 20.19.15.4531 / 2017.3068 / en_CA | CA | en_CA | en

10:30:31.497  Loading project from:   C:\Users\cornt\Documents\Corona Projects\StarExplorer

10:30:31.497  Project sandbox folder: C:\Users\cornt\AppData\Local\Corona Labs\Corona Simulator\Sandbox\starexplorer-DF93B5D2B56CED2D3D4D76A5BB8FE9C5\Documents

10:30:31.513  ERROR: Syntax error

10:30:31.513  C:\Users\cornt\Documents\Corona Projects\StarExplorer\main.lua:89: ‘(’ expected near ‘local’

This is line 89: local newAsteroid = display.newImageRect( mainGroup, objectSheet, 1, 102, 85 )

It is under Asteroid Creation.

Can someone tell me what is wrong with my code

You need to have a set of parenthesis at the end of line 88.

local function createAsteroid

should be

local function createAsteroid()

Rob

Thanks it worked :slight_smile: .

You need to have a set of parenthesis at the end of line 88.

local function createAsteroid

should be

local function createAsteroid()

Rob

Thanks it worked :slight_smile: .