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

What is the use of ()?

Asked by 10 years ago

I use this in some scripts but i want to know the meaning of it. Like

Testing.MouseButton1Down:connect() 

And why do we put some thing inside the braket? I dont put anything but i see some script does. Please tell me what does it mean. Thank you for reading or answering :)

3 answers

Log in to vote
3
Answered by
Ekkoh 635 Moderation Voter
10 years ago

In Lua we use ()s to define and call functions. For example,

function printName() -- the ()s are used when defining a function
    print("Name: Walter White")
end
printName() -- also used when calling the function

> Name: Walter White

Since you're also wondering about arguments and parameters-

function printName(name) -- still used here, but now we have a parameter called 'name'
    print("Name: " .. name)
end
printName("Jesse Pinkman") -- again, still used here, but now we pass it an argument, "Jesse Pinkman"

> Name: Jesse Pinkman

In your example case, MouseButton1Down was an event, I'd suggest reading the wiki page on them.

Arguments and Parameters

0
+1 Because of breaking bad reference Destrings 406 — 10y
0
Hi if you are reading this can you help me in this script? https://scriptinghelpers.org/questions/27135/script-wont-work PlayingOBC 70 — 9y
Ad
Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

Parenthesis serve two functions in Lua, both of which are also found in mathematics with this notation!

1. Grouping operations, to evaluated in an order other than PEMDAS, e.g., x * (y + a) is not the same as (x * y) + a.

2. Function application, like in sin(x) in mathematics. Lua uses the same convention of <functionname>(<functionparameters>). Juxtaposing a value with parenthesis in Lua always means function application, not multiplication:

(x+1)(x+2) does NOT mean (x+1)*(x+2). It means apply (x+2) to the function (x+1) (which would only run without errors with strange metamethods).

They also appear in definitions of functions, although in that case it's a syntactic structure rather than actual application!

In the specific example you gave, we call that a method call instead of a function call because it acts slightly different, but operation is almost exactly the same:

a:b(c) is the same thing as a.b(a,c) (which is a regular function call).

Log in to vote
-1
Answered by 10 years ago

The first part that you see before the ':' is the action. For example, script.Parent.ClickDetector.MouseClick. Then you stick :connect() behind it. The thing that goes in the brackets is a function that you made. So the finished thing would be this, if 'rek' was my function. script.Parent.ClickDetector.MouseClick:connect(rek)

0
Thanks for explaining me about it :) PlayingOBC 70 — 10y

Answer this question