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

What is a parameter and how does it differ throughout different events?

Asked by 7 years ago

I've been scripting for a few months, and I know how scripts work such as if someone writes

part = game.Workspace.part

part.Touched:connect(function(hit)
    hit.Parent.Humanoid.Health = 0 


end)

it'll kill the character and hit is the person who touched the part.

But when you're using GUIs and there are three parameters, I'm starting to wonder what these actually are so that I can use them correctly.

Can anybody describe them for me?

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

What are parameters?

Parameters are the input for functions. They are predefined data holders for the arguments that the function will be called with.

function blah(a) --Parameter
    print(a+2);
end

blah(5) --Argument
--Output: 7

How do they differentiate between events?

Parameters for the functions that you connect to events are extremely useful, and most of the time a necessity for your code. These represent whatever the event returns.

ex

Here's a couple examples -

  • Touched event : returns the part that touched
function onTouch(hit) --Parameter for event
    print(hit.Name.." touched "..script.Parent.Name)
end

script.Parent.Touched:Connect(onTouch)
  • MouseClick event : returns the player who clicked
function onClick(who) --Parameter
    print(who.Name.." clicked "..script.Parent.Name);
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)
  • PlayerAdded event : returns the player that joined
function onPlayerEntered(plr) --Parameter
    print(plr.Name.." joined the server!");
end

game.Players.PlayerAdded:Connect(onPlayerEntered)

-Edit-

To define multiple parameters, separate variable phrases by , commas.

function sayhi(who,when) --multiple parameters separated by commas.
    print(who.." said hi at "..when.." o'clock")
end

sayhi("Bob","2:00") --call it with multiple arguments
--Output : Bob said hi at 2:00 o'clock
0
Thanks, though, do you know how the multiple parameters work? Shadi432 69 — 7y
0
edited Goulstem 8144 — 7y
Ad

Answer this question