I sometimes see in scripts return false
and return true
, what are they used for, and how do they work? I see them in functions mainly.
Returns are a way of getting information out of a function. For example:
function add(a,b) return a+b end
This will add 2 numbers, then return the result. Now, if we do this:
add(1,3)
Lua will see it as "4".
A more practical example:
function add(a,b) return a+b end print(add(3,7)) --output: 10
You can use this with booleans as well.
local thing = false function check() if thing == false then return false else return true end end print(check()) --output: false thing = true print(check()) --output: true