Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is `return false` and `return true` for?

Asked by 10 years ago

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.

1 answer

Log in to vote
1
Answered by
MrFlimsy 345 Moderation Voter
10 years ago

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
0
Thanks man! I wasn't too sure of what `return` was used for, this helps allot! +1 TheeDeathCaster 2368 — 10y
Ad

Answer this question