use of the semicolon

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

use of the semicolon

Post 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.
User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Re: use of the semicolon

Post 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.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: use of the semicolon

Post 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.
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: use of the semicolon

Post 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
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: use of the semicolon

Post by Isaac »

http://lua-users.org/wiki/LearningLua

**But Grimrock seems a subset of Lua, with added game specific functions, and some omissions.
Last edited by Isaac on Wed Nov 04, 2015 10:14 am, edited 1 time in total.
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: use of the semicolon

Post by petri »

IMHO semicolons at the end of line are ugly and completely unnecessary.
User avatar
gambit37
Posts: 218
Joined: Fri Mar 02, 2012 3:40 pm

Re: use of the semicolon

Post 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... ;)
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: use of the semicolon

Post 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 ;)
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: use of the semicolon

Post 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!
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: use of the semicolon

Post 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
Post Reply