Page 1 of 2

use of the semicolon

Posted: Wed Nov 04, 2015 9:35 am
by FeMaiden
I guess this is a lua syntax question.

I've seen other scripts, not my own that use the semicolon at the end of each line.

I'm confused what does this do and why is it necessary(or unnecessary)

I noticed when I do

Code: Select all

function freeze()
GameMode.setGameFlag("DisableMovement",true)
GameMode.setGameFlag("DisableMonosterAI",true)
end
and when I do

Code: Select all


function freeze()
GameMode.setGameFlag("DisableMovement",true);
GameMode.setGameFlag("DisableMonosterAI",true);
end


they both work.
so if the code can work with or without the semicolons, why use them? I'm sure I'm missing some detail here.

Re: use of the semicolon

Posted: Wed Nov 04, 2015 10:00 am
by gambit37
They're optional in Lua. Unless you're writing multiple statements per line. Here's some more info:

http://stackoverflow.com/questions/1686 ... onventions

Do you know Lua basics? It's useful to learn those before getting too deep into Grimrock modding.

Re: use of the semicolon

Posted: Wed Nov 04, 2015 10:07 am
by Isaac
In other languages like C and javascript, it's important, in Lua [afaik] it's an optional end of statement.

print("hello", "world") is fine, but
print("hello"; "world") is not. Lua expects the ending parentheses of the print statement before the semicolon; and then expects the [next line's] function name of what follows the semicolon before the ending parameter and parenthesis.

Re: use of the semicolon

Posted: Wed Nov 04, 2015 10:10 am
by FeMaiden
gambit37 wrote:They're optional in Lua. Unless you're writing multiple statements per line. Here's some more info:

http://stackoverflow.com/questions/1686 ... onventions

Do you know Lua basics? It's useful to learn those before getting too deep into Grimrock modding.

I see,

well, I don't know what constitutes "lua basics"
I do know i've learned a lot over the past couple of weeks but, this is probably why i'm having trouble with this. I never actually "learned" anything about lua before I attempted to make a custom dungeon for grimrock

Re: use of the semicolon

Posted: Wed Nov 04, 2015 10:12 am
by Isaac
http://lua-users.org/wiki/LearningLua

**But Grimrock seems a subset of Lua, with added game specific functions, and some omissions.

Re: use of the semicolon

Posted: Wed Nov 04, 2015 10:13 am
by petri
IMHO semicolons at the end of line are ugly and completely unnecessary.

Re: use of the semicolon

Posted: Wed Nov 04, 2015 10:27 am
by gambit37
One doesn't need to learn much about Lua before modding Grimrock, as it's a pretty easy language to pick up. But like spoken languages, it's useful to know the grammar and rules behind how a sentence is constructed.

Browsing the forums, it seems many modders come unstuck on Lua because they've not taken the time to learn its 'grammar' before charging in headfirst. There's a certain amount that can be learned by poking around, but at some point it's wise to read some Lua documentation, otherwise we never get beyond the tinkering stage.

And I agree with Petri: semi colons are ugly. Though I now get really confused when switching between Lua for modding and JavaScript in my day job... ;)

Re: use of the semicolon

Posted: Wed Nov 04, 2015 11:11 am
by petri
gambit37 wrote:Though I now get really confused when switching between Lua for modding and JavaScript in my day job... ;)
I think you'll soon wish you could use Lua in your daily job. It beats javascript pretty much hands down ;)

Re: use of the semicolon

Posted: Wed Nov 04, 2015 11:34 am
by JohnWordsworth
I think the only reason you see them nowadays (apart from when you have multiple statements per line) is force of habit.

As I only bash out Lua here and there, my code is littered with semi-colons, but now I do some Swift coding too - I'm starting to get rid of them. I think it's slightly more visually pleasing without, but as long as it's consistent within a given file - I don't really care either way!

Re: use of the semicolon

Posted: Wed Nov 04, 2015 11:46 am
by FeMaiden
JohnWordsworth wrote:I think the only reason you see them nowadays (apart from when you have multiple statements per line) is force of habit.

As I only bash out Lua here and there, my code is littered with semi-colons, but now I do some Swift coding too - I'm starting to get rid of them. I think it's slightly more visually pleasing without, but as long as it's consistent within a given file - I don't really care either way!
ahh john wordsworth, you are the creator of the GrimTK gi toolkit aren't you. have you read my other post? i'm having problems getting it to work in my main project, I can make it work perfectly when I create a new projects, but in my main projectI can't get it to recognize the commands