What does " ; " do in scripts?

Hello, so I have seen a lot of scripts that have " ; " at the end of each line. What does it do?

Im pretty sure it just means its the end of that line but I might be wrong

For example

local Variable1 = 1;
local Variable2 = 2;
local Variable3 = true;

Or sometimes when a lot of code is on one line, it is like this:

local NewPart = Instance.new('Part') ; NewPart.Position = Vector3.new(1,5,4) ; NewPart.Parent = workspace

What does it even do?

1 Like

Usually it is just purely cosmetic. Some people might use it in Roblox Lua because they got used to using semicolons at the end of lines of code. Some programming languages like C++ need semicolon at the end of every command and some programmers could move this habbit to Roblox Lua.

3 Likes

In normal scripts or ModuleScripts?

1 Like

In roblox it’s just to make it feel like other languages, in other languages it’s used to end a line as far as I know.

2 Likes

Actually, it acts more like a separator. Current style guides do not really advise this to be used, but it only fits in niche usages.

3 Likes

We use this in JavaScript:

const a = 100;
var b = 10;
let c = 1;

parseInt("102");

Its just there to determine where the line/statement ends, and afaik in lua, it can also be used in tables to define an index (pretty sure other languages do that, but idk):

{
    a = 1;
    b = 2;
    -- and so on
}

As far as I was told, in most languages, they dont use it the same way as other languages, in which some of them use a semicolon to define the end of a statement.
Otherwise it just mostly acts as a thing you use to easily read your code.

I dont think Lua is one of those languages, but my habits still kick in from JavaScript:

local this = true;
local that = 281902;

thisFunction();
3 Likes

Oh yeah that makes more sense. I appreciate all of the replies

So its just preference?

As far as im concerned for lua, it’s a preference, but there is a few things It can be used for, like I mentioned:

But that can just as easily be replaced with a regular comma.
I only ever use it to define an end statement like I have for outside languages, its just easier for me to understand and read, but I can’t say the same for everyone else.

1 Like

Languages like Lua and Python are identation based, and because they’re high level languages, they do not require “;” generally. (Though in some cases the VM/Type checker may require you to use it)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.