I have function in which perform arithmetic on standart numbers.
1 | function arithmetic(formula) |
2 | x = 1 |
3 | y = 10 |
4 | z = formula |
5 | print (z) |
6 | end |
7 |
8 | arithmetic(x+y) |
The problem is: it starts to count in function variables, when x and y are nil, and error happens because x and y are nil at the first line.
So i want to perform arithmetic only when i want to, in this case only on line 4.
x & y are not defined globally in the script in line 8. When you're calling a function, it takes in arguments for the function to play with.
1 | function Arithmetic(x, y) -- Parameters for arguments |
2 | local Solution = x + y |
3 | print (Solution) |
4 | end |
5 | -- At this point, the function is defined; the output will spit out the solution when it is called. |
6 |
7 | Arithmetic( 1 , 10 ) -- Here, the defined function "Arithmetic" is called, taking 1 and 10 for x and y respectively. |
11