Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Brackets but not parentheses?

Asked by
emite1000 335 Moderation Voter
10 years ago

Why does the line script.Parent["Left Arm"].Anchored = false work, but when I replace the brackets [ ] with parentheses ( ), it no longer works?

2 answers

Log in to vote
4
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Brackets and parenthesis are never equivalent in Lua syntax. If they were interchangeable, it would result in ambiguity, which would make programming impossible.


script.Parent("Left Arm") syntactically works the same as print("Left Arm"): Juxtaposing parenthesis means function call which is not what you mean when you say script.Parent["Left Arm"].

Brackets, on the other hand, refer to table (+ child/property) indexing.

Because you need to be able to express both of these things, and in any & all events only one of them, parenthesis and brackets have to be separate in their meanings.



Other uses of Parenthesis / Braces / Brackets (Not directly relevant to question)

For thoroughness I'll mention the other uses of parenthesis / brackets / braces that were not mentioned by you.

Parenthesis also accomplish grouping of operations, e.g., (5 + 3) * 2 is 16 and 5 + 3 * 2 is 11.

Double square brackets are used to create multiline strings which ignore escape sequences:

local str = [[Hello
this is a long
string]]

Those are also used to make multiline comments:

--[[ I have a lot to say
about this particular
piece of code]]

Curly braces ({ and }) are used in Lua to define table literals, e.g.,

local list = {2,3,5,7,13,17,19}
0
Thank you! This is exactly what I was looking for! Going into detail on that last part really helped also. emite1000 335 — 10y
0
Omg I just realized I just had my question answered by the person who makes my favorite ROBLOX Portal game! o.O :D emite1000 335 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

I believe only brackets work, not ().

Answer this question