Answered by
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.
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
2 | print (hit.Name.. " touched " ..script.Parent.Name) |
5 | script.Parent.Touched:Connect(onTouch) |
- MouseClick event : returns the player who clicked
2 | print (who.Name.. " clicked " ..script.Parent.Name); |
5 | script.Parent.ClickDetector.MouseClick:Connect(onClick) |
- PlayerAdded event : returns the player that joined
1 | function onPlayerEntered(plr) |
2 | print (plr.Name.. " joined the server!" ); |
5 | game.Players.PlayerAdded:Connect(onPlayerEntered) |
-Edit-
To define multiple parameters, separate variable phrases by ,
commas.
1 | function sayhi(who,when) |
2 | print (who.. " said hi at " ..when.. " o'clock" ) |