Jump to content
  • Advertisement
Sign in to follow this  
apefish

Lua syntax error

This topic is 3349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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,...)

blabla
end

function MT.switch
....

function new_scenemanager()
return MT
end




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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!