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

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

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

✓ Accepted answer

###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

2 comments

0

Thanks, though, do you know how the multiple parameters work?

0

edited

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