expected near error

I'm trying to test out this level but am having trouble getting it to load. I am getting an error ) expected near , in this line of code

local spawnPlayerObject(xPlayerSpawn, yPlayerSpawn, richTurn)

I am trying to use director class for level transitions and such as well. any help would be great. Thank you

Are you trying to declare a function, then use this syntax:

local function spawnPlayerObject(xPlayerSpawn, yPlayerSpawn, richTurn)

end

Check this article to understand functions:

http://developer.anscamobile.com/content/events-and-listeners#Function_vs_Table_Listeners

Hope this helps.

Thanks that fixed that part, but now its saying table expected on

localGroup:insert(background)

heres the whole thing

function new()
localGroup = display.newGroup()

local background = display.newImage('1_0.png', true)
localGroup:insert(background)

thanks again

it seems like its not recognizing the localGroup or something along those lines

Could you post the complete code.. Difficult to make out the issue with posted code snippet

cheers,
Bejoy

ok sure

module(..., package.seeall)

--local background = display.newImage("1_0.png", true)
Sturret = require("Sturret")
local Sturret
local spawnLevelEnd
local spawnPlayerObject
--require("Rich")
local levelComplete = false
local playerDir = 0
playerSpawnX = 0
playerSpawnY = 0
leveltime = {}
leveltime[1] = 30
dotting = false
local canDraw = true
arrowsLeft = 8
drawnLines = 0
posCount = 1
local fireTime = 0
currentLevel = 1
local playerSpeed = 0
local player
local rich
local richDir = 0
require "sprite"
local richSheet1 = sprite.newSpriteSheet("richClimb1.png",216,360)
local localgroup

function new()
localGroup = display.newGroup()

local background = display.newImage('1_0.png', true)
localGroup:insert(background)

--function levelZeroLoad()
--bakground image PLACEHOLDER
--print((_W/320), _H/480)
--background = display.newImage( "1_0.png", true)
--background.x = 0*_W/320+_W/2
--background.y = 0*_H/480+_H/2
--background:scale(display.contentWidth/320, display.contentHeight/480)
--background:setReferencePoint(display.TopLeftReferencePoint)
--background:toBack()
--localGroup:insert(background)

--spawn Player X and Y coords

local function spawnPlayerObject(xPlayerSpawn, yPlayerSpawn, richTurn)
local richPlayer = sprite.newSpriteSet(richSheet1,1,6)
sprite.add(richPlayer, "rich", 2,5,500,1)
rich = sprite.newSprite(richPlayer)
rich.x = xPlayerSpawn
rich.y = yPlayerSpawn
rich:scale(_W*0.0009, _W*0.0009) -- scale is used to adjust the size of the object.
richDir = richTurn
rich.rotation = richDir
rich:prepare("rich")
rich:play()
physics.addBody( rich, { friction=1, radius = 15 } ) -- needs a better physics body for collision detection.
localGroup:insert(spawnPlayerObject)
end

--level end location X and Y coords
local function spawnLevelEnd(xEndSpawn, yEndSpawn) -- the end of level point code is here. what still needs to be done is the loading of the next level on completion.
endLevel = display.newCircle( xEndSpawn, yEndSpawn, 10 )
physics.addBody( endLevel, "static", { friction=1 } )

localGroup:insert(endLevel)

endLevel.scene = "1-1"
endLevel:addEventListener("touch", changeScene)
end

return localGroup
end

heres all the code in the file

Could you also post the error message. I do not see any error with localGroup declaration and insert method..

it says ERROR:table expecte, if this is a function call you may have used . instead of :

easier to read

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
ok sure
 
module(..., package.seeall)
 
--local background = display.newImage("1_0.png", true)
Sturret = require("Sturret")
local Sturret
local spawnLevelEnd
local spawnPlayerObject
--require("Rich")
local levelComplete = false
local playerDir = 0
playerSpawnX = 0
playerSpawnY = 0
leveltime = {}
leveltime[1] = 30
dotting = false
local canDraw = true
arrowsLeft = 8
drawnLines = 0
posCount = 1
local fireTime = 0
currentLevel = 1
local playerSpeed = 0
local player
local rich
local richDir = 0
require "sprite"
local richSheet1 = sprite.newSpriteSheet("richClimb1.png",216,360)
local localgroup
 
function new()
localGroup = display.newGroup()
 
local background = display.newImage('1_0.png', true)
localGroup:insert(background)
 
--function levelZeroLoad()
--bakground image PLACEHOLDER
--print((_W/320), _H/480)
--background = display.newImage( "1_0.png", true)
--background.x = 0*_W/320+_W/2
--background.y = 0*_H/480+_H/2
--background:scale(display.contentWidth/320, display.contentHeight/480)
--background:setReferencePoint(display.TopLeftReferencePoint)
--background:toBack()
--localGroup:insert(background)
 
--spawn Player X and Y coords
 
local function spawnPlayerObject(xPlayerSpawn, yPlayerSpawn, richTurn)
local richPlayer = sprite.newSpriteSet(richSheet1,1,6)
sprite.add(richPlayer, "rich", 2,5,500,1)
rich = sprite.newSprite(richPlayer)
rich.x = xPlayerSpawn
rich.y = yPlayerSpawn
rich:scale(_W*0.0009, _W*0.0009) -- scale is used to adjust the size of the object.
richDir = richTurn
rich.rotation = richDir
rich:prepare("rich")
rich:play()
physics.addBody( rich, { friction=1, radius = 15 } ) -- needs a better physics body for collision detection.
localGroup:insert(spawnPlayerObject)
end
 
--level end location X and Y coords
local function spawnLevelEnd(xEndSpawn, yEndSpawn) -- the end of level point code is here. what still needs to be done is the loading of the next level on completion.
endLevel = display.newCircle( xEndSpawn, yEndSpawn, 10 )
physics.addBody( endLevel, "static", { friction=1 } )
 
localGroup:insert(endLevel)
 
endLevel.scene = "1-1"
endLevel:addEventListener("touch", changeScene)
end
 
return localGroup
end

first remove line 11 and add local to line 10

line ten is commented out right now are you saying i should activate it and add local. I did do that and am now getting an error of syntax error near on the next active line of code

sorry line numbers don't line up on iphone

Sturret = require("Sturret") --- add local here
local Sturret --- remove this line

ok i did that but i'm still getting the syntax error

i fixed it but I'm back to getting this error, ERROR:table expecte, if this is a function call you may have used . instead of :

what line number is the error on

it's localGroup:insert which is 36 above

still looking at code but
take a look a spritegrabber in code exchange it makes dealing with spritesheets easier

try moving local localGroup to under function new()

the same error is appearing with that as well

views:2116 update:2011/11/5 17:18:39
corona forums © 2003-2011