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

can someone explain me about parameters?

Asked by 3 years ago

so when i was using function then i asked myself what parameters are is it for function like the following code? local function name()

print("function")

end

name()

-- what does that () means in local function name

2 answers

Log in to vote
0
Answered by 3 years ago

Basically If you were to do "local function name(string)" and you also done "print(sting)" if you were to call it like "name('Hello World!')", So the parameters are basically variables defined when you call the function with arguments.

Ad
Log in to vote
0
Answered by 3 years ago

Some functions allow you to put variables in the bracket so you can make them more portable in use. Not all functions need them, however but some do.

Let's look at these two functions:

-- no arguments
local number1 = 2
local number2 = 3
local function add()
     print(number1 + number2)
end

add()

That function was wasteful, why? Because we used two variables which we may never ever need again. However I used add() with empty brackets because it has no parameters.

-- with arguments
local function add (number1, number2)
     print(number1 + number2)
end

add(2, 3)
add(5, 7)

See, now I can add any two numbers I want and don't need to create two variables for it. It's portable because numbers 1 and 2 are just parameters I put into the function.

Answer this question