Ok so I don’t know if () does anything in if statements. Does it prevent memory leaks from objects or something? Anyways here’s the example code.
if (Frame.Visible == false) then
-- do something
end
Ok so I don’t know if () does anything in if statements. Does it prevent memory leaks from objects or something? Anyways here’s the example code.
if (Frame.Visible == false) then
-- do something
end
It doesn’t really do anything. It’s used to group things together in Lua. In things like JavaScript, you do need to put those parentheses when you’re doing an if-statement; however, in Lua, you don’t need to do that. If you want, you can use the parentheses in Lua to group conditions for your if-statement together, e.g.
if (condition1 and condition2) or condition3 do
-- stuff
end
It’s not better practice to include it by default like @chexedy said. That’s wrong. It’s just a personal preference.
It’s an optional thing to do when doing conditions. It’s only required on certain languages such as Javascript and C++. you don’t really need it unless you want to have that kind of coding style.
It’s not better practice. It really does nothing.
By the way the Roblox Lua style guide actively discourages this, as they are not necessary.
As mentioned above it is usually just a habit people carry over from other languages, that is also the same reason why you may see people use semicolons. Whether or not it’s a good habit is a different story. Although semicolons only have two real uses in all of Lua
local x = 7/(2 + 1.5)
(function()
print(x)
end)()
(is this calling the number 3.5 or is the literal function call its own statement?) but you shouldn’t be programming like this anywayJust wanted to double this and say yeah the lua style guide is a recommendation, but I personally use () because of my previous experience with c++/c# and javascript
It also helps me structure my code better in my opinion when I am doing mathematical operations or complex if statements.
Fun fact you can call a function like this if it has a parameter.
SomeFunction"can be called like this"
I would somewhat disagree, I use JavaScript and I didn’t have any trouble switching, but I feel that new developers would have an easier time switching if they practiced stuff like that.
Nothing. An example of using it would be.
local Number = 4*(2+2)
local Number1 = 4*2+2
Number = 16, Number1 = 10.
I’m not saying it’s bad or anything, you can script in whatever style you want. I’m saying that it doesn’t affect your code very much, unless your doing math (then parenthesis would be necessary).
I actually like the parenthesis, in fact it makes code like 3x more satisfying to look at.
I don’t write code in that style though, for off topic reasons.
It is better practice if you wish to do more development outside of roblox, such as kotlin, java, ect.
It doesn’t do anything. Just like a semicolon in javascript.
Jesus, that looks so weird considering how often I use parenthesis.
Yeah your not supposed to do that. The only time people ever really use it is when they want to show off how bad their code looks.
Yes it’s a very bad practice. But you can also call a function like this.
Hey! what tutorial site is that?
I just searched the highlighted text and it is on Roblox’s github page.