What exactly is a parameter?

Could you give me a link/example of where they use it? Parameters aren’t always the same, it depends on the situation.

Ok. And btw, I noticed that the Roblox Developer learning hub, they use a lot of “otherPart” Parameters. What is (otherPart) supposed to be?

  1. local lava = script.Parent
  • local function killPlayer(otherPart)
  • end
  • lava.Touched:Connect(killPlayer)
1 Like

A parameter is basically like placeholder values that you give into the function, then when you call the function, the placeholder parameters are turned into these values, for example

local function AddNumber(num1, num2) --creating 2 parameters to hold values that will become the actual numbers
    return num1 + num2 --just adding the placeholder values, which will soon be replaced by actual numbers when called
end

print(AddNumber(2, 3)) --prints 5, as we told the function to add the placeholder parameters
2 Likes

A function is a group of code, it is named, and it performs a task that you have created it for.

Sometimes functions need information to do their job.

If a line of code calls a function to do a job, it might pass it the information it needs. The information passed, as listed on that line of code, is called an “Argument”.

When the function receives the information, at the function, it is called a “Parameter”.

The line of code “has an argument” for the function.
The function "needs to know its parameters.

1 Like

That’s called a parameter, it’s a value that is returned by the .Touched Event. Different events return different values. In this case, .Touched returns the BasePart that collided. Parameters are variables too, so you can rename otherPart to “coolPart” or just “Part”

1 Like

Ah I see. You’re trying to make a kill touch part.

The lava part you’re using can be touched by players and can be made into events using lava.Touched. When the lava is touched, it’s touched by a part of the player’s character, for example; the left leg, or right arm, etc.

So in this case, the argument otherPart refers to the part touching the lava.

1 Like

So parameter sort of gives the function value and more information on what to do?

so for instance, “sortGarbage” is the function and (trash, recyclable) is the parameter which tells the function how to sort it out?

  1. local function sortGarbage(trash, recyclable)
  2. print(“garbage test”)
  3. end
  • sortGarbage()

It’s the thing that goes in function brackets.

In computer science, a parameter is a value, coming from a variable or a more complex expression, that can be passed to an internal function (subroutine), which uses the parameter values ​​to change the behavior at runtime. .

parameter = local function (things here)

1 Like

Like this:

--// Let's say you want to call something
local function myFunc(message)
    print(message) --// Prints 'Message Is Here'
end

myFunc("Message Is Here")
1 Like

The parameter is basically the value passed on the function. Let’s say I wanna make a function that runs everything I feed it, I’ll be able to use parameters like this…

function Run(Code)
   loadstring(Code)();
end;

Run(print("yo"));
1 Like

So you’re saying a parem is just a variable but for more use?

1 Like

Pretty sure that isn’t luau, last time I ever saw somebody having semicolons after each line was in c#.

1 Like

Yes, it’s personal preference. I just like putting semicolons after each line, although it’s not needed. I’m used to it.

2 Likes
function printMessage(message) --message would be the parameter here
    print(message)
end

printMessage(Hello world!) -- prints out Hello world! inside the console

In simple terms, we’re basically just trying to set message to a variable, and printing out that variable, then whenever we call the function, we can specify the value of that variable. (also please don’t get parameters and arguments mixed up, message would be the parameter and Hello world! would be the argument in this case.)

1 Like

Please do keep in mind that arguments and parameters are different things, an argument is the value that you specify and a parameter is the variable that you’re going to set the value of.

2 Likes

So is the argument inside the parameter in a way? Like is the parameter the “Parent” and the argument is a “Child”?

1 Like

Oh yes, I see now. Sorry for not pointing that out before, the difference between the both is so small that I forgot it.

2 Likes