Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is the use of ()?

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

✓ Accepted answer

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

2 comments

0

+1 Because of breaking bad reference

0

Hi if you are reading this can you help me in this script? https://scriptinghelpers.org/questions/27135/script-wont-work

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).

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)

1 comment

0

Thanks for explaining me about it :)

This discussion is preserved as it was. New answers, comments, and votes are closed.