# Lua syntax error

## Recommended Posts

Hi, I have this piece of lua code that i wrote that has a syntax error but i can't figure it out: function new_scenemanager() return { function setstart(self, startscene, ...) return self.current = startscene(self, ...) end function switch(self, newscene, ...) self.current:unload() return self.current = newscene(self, ...) end function run(self) while self.current:update() do end --update returns false to close the application self.current:unload() end } end The lua interpreter complains about line 3; "'(' expected near 'setstart'". The problem is that there is already a '(' near 'setstart' so i don't know why it's complaining. If i change it to "setstart = function(self, startscene, ...)" it complains about not having an 'end' to close the function. If anyone can spot what the problem is that would be great.

##### Share on other sites
hmmm..

You're sure that you wrote the code? Not calling you a liar, but (I may be mistaken) the code has some newbie errors, and at the same time is a little complex..

the new_scenemanager function returns a table, but you don't put a ',' between elements.

why don't you do something like:
local MT={}function MT.setstart(self, startscene,...)blablaendfunction MT.switch....function new_scenemanager() return MTend

also:
function setstart(self, startscene, ...)
return self.current = startscene(self, ...)

it should be something like:

function setstart(self, startscene, ...)
return self.current = startscene(self, args)

##### Share on other sites
I don't think you can do

return self.current = startscene(self, ...)

in lua. I beleive it should be like

self.current = startscene(self, args)return self.current

##### Share on other sites
Thanks for the tip on the commas, what a dumb mistake. Yes i did write this code and i am a lua n00b (hence the lack of commas).

As for the ... vs args I don't know; in the reference it says ... is the new way to do it (Lua 5.1), but then of course there's nothing about it in the books you can get online.

hmmm. If Lua can't do that return it's a bit disturbing, I'll experiment. I'm used to C where everything is an expression.

Thanks alot for your tips, I'll see If i can get it working now.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628400
• Total Posts
2982446

• 10
• 9
• 19
• 24
• 10