I see returning a lot especially in functions, what does it do? Is it useful? Any explanation is appreciated.
Returning is used to send informations back to where the function is called, here is an example:
local function sayHi() return "Hi!" end -- Print returned value of sayHi local returnedValue = sayHi() print(returnedValue)
Here is the expected output:
Hi!
You can also return using integers, as well as performing arithmetics.
local function multiply(x, y) return x*y end local returnedValue = multiply(5, 5) print(returnedValue)
25
Returning is very simple and easy to learn and very useful.
You don't have to wrap in a variable print(multiply(5, 5))
Quick Recap: Returning is used to send informations to where the function is called, so whatever your returned value is, that value will get sent.
There's a really good Lua documentation page for exactly what you're looking for. https://www.lua.org/pil/4.4.html