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

Am I correct about Parameters and Arguments?? Learning about want, experts opinion?

Asked by 5 years ago

Okay, so I have been watching peasfactory. And, I am learning about Parameters and Arguments. I wanna tell what I think they are, and please feel free to fix/ give more info needed. Gonna be very basic cause I am new.

Basically, when you call a function so

test() -- what is in the "()" is a variable. And that variable can only be used inside of the particular function it is in. However to call it you need to give it a value. The value is the argument. Don't know much about argument, sept its the value of the variable, and I think it is assigned outside the function?? Or can it be assigned inside, or out?? THANKS.

1 answer

Log in to vote
1
Answered by 5 years ago

Arguments are the variables created by functions. Parameters are the definitions of those variables. In methods like FindFirstChild(), you only have to type in the Instance parameter (and, if you want, the boolean recursive parameter). Example:

if game.Workspace:FindFirstChild("Part") ~= nil then
    print("part found")
end

"Part", the string put in as the parameter to the Instance argument, defines Instance as a Part in the Workspace. All methods require you to fill in just a parameter.

Functions

Functions are a bit different from methods. Functions require you (if you want) to give it an argument AND fill in a parameter for that argument. Example:

function Roblox(oof)
    print(oof)
end

Roblox("oof")

The tricky thing with parameters to function arguments is that they can be any value possible. In the function Roblox(), the argument "oof" was defined by the parameter "oof" (a string). Most parameters define the arguments outside the functions.

Exceptions?

The most talked-about exception to being defined outside the function is defining it inside the function. This is not possible. You can spread the argument around the function however you want, but if you want a parameter for it that parameter must be outside the function. Example:

function Round(num, addend) -- You can have more than one argument
    return math.floor(num + addend)
end

Round(6.5, 0.5)

This function uses the two arguments it produced and sets them as nil until the parameters are set for them. In this case, we are rounding 6.5 to 7 by "tricking" math.floor(). If you have any questions, please ask them.

Thanks, MCAndRobloxUnited

0
You have them confused. Arguments are what you pass to the function call. Parameters are in the definition of the function User#24403 69 — 5y
0
read the lua manual DeceptiveCaster 3761 — 5y
0
you rely too much on the wiki DeceptiveCaster 3761 — 5y
0
don't forget basic lua and roblox lua may be the same language, it still has a few difference, and the naming in roblox might be one, I agree with sjr04Alt on this (even though this would still be correct) User#20388 0 — 5y
0
parameters are also defined even without a fill-in (e.g. player added) DeceptiveCaster 3761 — 5y
Ad

Answer this question