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

So what exactly is the difference between an argument and a parameter?

So as I've been doing lua for the last year or so, I've never understood the difference between an argument and a parameter. I set up functions like this

Variable.Event:connect(function()

end)

rather than

function Derp 

end

Variable.Event:connect(Derp)

I know that arguments and parameters depend on how you set it up which is why i showed my method of setting up a function. Not really a big difference at this point, but i would still like to know

1 comment

0

No, there is a differnce

3 answers

✓ Accepted answer

Arguments are values passed into a function, parameters are upvalues (basically local variables) defined in the function definition, which hold the passed-in arguments.

In terms of the connect function of ROBLOX Events, it takes a single argument: the function to connect to the event.

This might not seem correct when looking at anonymous function connections:

script.Parent.Touched:connect(function(hit)
	print(hit)
end)

But this still holds true, since functions in Lua are first-class values


In the case of ROBLOX events, you only set the parameters of the function. Touched, for instance, passes in to your provided function one argument: the 'other' Part that collided with the owner of the Touched event itself.

To answer your question, parameters are the "variables" that you define in the parenthesis of a function.

local function boop(one, hello)
--one and hello are parameters
end

Arguments are whatever values you pass to those parameters.

local function boop(one, hello)
print(one,hello)
end

boop("monkey","banana") 
--monkey and banana are arguments

Roblox events pass arguments to any parameters of a connected function, For example, the Touched Event passes whatever touched the specified object as an argument to the first parameter of the given function.

local part = Instance.new("Part",workspace)

part.Touched:connect(function(hit) --prints whatever touched the part
print(hit)
end

The only reason you would ever need to use an anonymous event rather than convenience over connecting the function to an event would be to call that function without that event passing any arguments to the function

local part = Instance.new("Part",workspace)

local function boop(p)
print(p)
end

part.Touched:connect(function(hit) --prints whatever touched the part
boop("Hello")--prints "Hello" when the part is touched, because "hit" is not a parameter of this function.
end

One reason you might want to avoid anonymous events is because you'd have to redefine your function. By defining it and then linking it to an event, you can use that function elsewhere, too.

local part = Instance.new("Part",workspace)

local function boop(p)
print(p)
end

part.Touched:connect(function(hit) --prints whatever touched the part
boop("Hello")
end

for i = 1,5 do
boop(i)
end

Basically if you make a function;

function printSomething(argument)
	print(argument)
end
printSomething('Hello world')

The function "printSomething" is calling the PARAMETER "argument". When I call "printSomething", the ARGUMENT is "'Hello world'".

Basically, the Parameter holds the value and the argument is the actual value.

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