What are Parameters

Hello! while I was in my little script learning journey I completely forgot about these things cald parameters, I know their in parentheses and stuff but, How do they work, what are they used for.

3 Likes

They’re used for getting information about what fired the event.

For example, .Touched returns the BasePart that fired the event.

basePart.Touched:Connect(function(part)
    print(part)
end)

If the part was the character’s left leg, it would print Left Leg. It doesn’t always return instances either. Another common use from the top of my head is the .InputBegan event of user input service which returns a boolean (fundamental datatype for most if not all programming languages). GameProcessed refers to if a textbox is focused and I think that’s it?

userInputService.InputBegan:Connect(function(inputObject, gameProcessed)
    if inputObject.KeyCode == Enum.KeyCode.D and not gameProcessed then
        print('D pressed and user was not in a textbox!')
    end
end)
4 Likes

“a numerical or other measurable factor forming one of a set that defines a system or sets the conditions of its operation.”

-Google definition

Parameters are things that need to be passed in order for a function to work. For example:

local cheese = 1
function eatCheese(amount) --amount is a parameter
    print("I ate " .. amount .. "cheeses!")
end
eatCheese(cheese)
2 Likes

wait, so does the variable cheese = amount since you passed it and then game it another alias?

Yes. Cheese is amount. Amount is 1. It’s like I give you a white ball that I call Jim, and then when you take it you decide to call it Martha. It is still the same ball, just differently named.

2 Likes

You can also put ... for tuple parameters. For example:

function say(...)
    print(...)
end

--call the function
say("Hello!", "Goodbye.", "How are you?") --the list can go on