We all know that arguments will be place inside the ( ) after the function. But the use of the argument really confused me. My dad explained that it is like math functions, such as: f(x) = x+1. X is 5. Function?
Is his statement true?
I would just like to clarify an argument versus a parameter. You can't have one without the other, but they are not synonymous terms.
Basically, a parameter is in the parentheses when you create the function, while an argument is in the parentheses when you call it.
function add(a, b) --Parameters print(a + b) end add(1, 5) --Arguments
Take a look at CodeTheorem's more in-depth video about this.
Well, an argument is basically additional information that the function, method etc (not only functions have arguments) might want to know to carry out whatever it's doing.
Take, for example, the TakeDamage method you can call on Humanoids.
Humanoid:TakeDamage
Naturally Roblox will not like that very much because you aren't specifying anything. Here's where arguments come in, as they are (in most cases) the universal way of adding extra information to otherwise abstract functions like this one. So we add an argument:
Humanoid:TakeDamage(25)
Which will cause the Humanoid to lose 25 health.
For functions, the arguments of a function are determined by the event that is calling it; Take for example the OnTouch event. When connected to a function, OnTouch has a argument that takes any word (most commonly used by scripters is 'hit', although it can be anything you want), as a reference to the object that touched the brick, for example:
function onTouch(hit) if hit.Parent:FindFirstChild('Humanoid') then -- Checks if hit's (presumably a body part of a player) parent (which, if it is a body part that was touched, would be the Character) has a Humanoid hit.Character.Humanoid:TakeDamage(25) -- If so, deals damage end end Part.Touched:connect(onTouch) -- Connector
, which will cause you to lose 25 health if you touch the brick.