July 2018
Beginner
202 pages
5h 42m
English
Functions can take arguments. An argument is some data that will be passed into the function. You have passed arguments to the print function before; it takes a single string argument. Calling print with an argument looks like this: print ('hello, world').
When you declare a function, you can place one or more variable names inside the parentheses that are used during the function declaration. These variables are the function arguments; they have a scope local to the function.
The following function takes in two numbers and adds them together:
-- Declare the function, takes two argumentsfunction AddAndPrint(x, y) local result = x + y; print (x .. "+" .. y .. "=" .. result)end-- Call the function a few timesAddAndPrint(2, ...