I understand how returns work but I don't understand what they are used for. If a person and print a variable to they output, why would they want to return it instead?
return
is used in functions to stop everything (loops, etc.) and, literally, return a value.
function add(a, b) return a + b end local sum = add(2, 2) print( sum ) -->4
So basically, add
runs, then it gives us the sum. This lets us set a variable to the function's result, as we did on line 5.
Comment with questions.