Why does the line script.Parent["Left Arm"].Anchored = false
work, but when I replace the brackets [ ] with parentheses ( ), it no longer works?
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.
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}