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.
COMMUNITY QUESTION
What is `return false` and `return true` for?
1 answer
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Thanks man! I wasn't too sure of what
returnwas used for, this helps allot! +1