What does ; mean?

1. So I’ve seen some code some code do something like local x = 3; and Im wondering what ; means. Is it decorative or does it actually serve a purpose?

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Ive tried googling & looking on dev hub as well as going through a bit of lua documentation. And I haven’t really found anything useful Any help would be apricated :slight_smile:
1 Like

It’s only for a decorative / shortening lines,
For e.g: you could use that, to do 2 different things in 1 line.

local Stt = instance.new("StringValue") ; Stt.Parent = game.Workspace;

Notice that you dont really have to use it:)

5 Likes

Actually you can do that without ;

local Stt = instance.new("StringValue") Stt.Parent = game.Workspace
2 Likes

Apparently, but most people use it in their codes, probably to make it look neater.

2 Likes

; is completely optional. It doesn’t add or do anything in your code. It’s simply visual.

2 Likes

One reason why people will put it in is because it’s required in some other languages. Lua doesn’t really need semicolons, but it is required in languages like c++. It essentially just is appended to the end of a command to let the compiler know where it ends. For example this is an example of “hello world” in c++.

#include <iostream>
int main()
{
  std::cout << "Hello, World!" << std::endl;
  return 0;
}

Those semicolons are after specific commands to the computer. If you didn’t put the semicolons on those lines, the code would give a syntax error. So if you were to use c++ a lot you might get in the habit of putting in semicolons. (my friend always puts semicolons for this reason)

Some of the code you see in lua that ends in semicolons probably comes from someone familiar with one of the other languages that requires them. They likely just put them in by habit or preference. They are also sometimes used to make separations more clear to a reader when used on a single line.

I think generally it’s best not to put in semicolons for languages that don’t need them unless it’s generally used just for the sake of consistency.

2 Likes

Without ; in C++ script might error because in the C++, the ; is useful to connect the one code to the other codes! and #include isn’t needed ; because the #include have the <>, so its too confusing with a ; in after of the #include code…

in the lua, it just a fragile code because : is more effective than ;.

you can read more detail in @tlr22 post