Functions can be really useful as they let us process/calculate huge amounts of data & return it, also if you include input arguments then they can potentially be reused multiple times over, which can reduce overall workload & increase workflow.
Creating Functions
Below I am going to show you how to create your own custom functions.
Classic Function
print hello world!
functionhello()print("hello world!")endhello()
Variable as Function
print hello world!
hello=function()print("hello world!")endhello()
Function with Input Arguments
print 6
functionplus(a,b)returna+bendprint(plus(2,4))
Input Arguments and Fallback
print 0.5, 5
functiondivideAndConquer(a,b,c)c=cor1-- if c equals nil then c equals 1return(a/b)*cendprint(divideAndConquer(2,4))-- 2 ÷ 4 x 1 = 0.5print(divideAndConquer(2,4,10))-- 2 ÷ 4 x 10 = 5