Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Tutorials/Types/Booleans

From FiguraMC

A boolean is a Lua value that is either true or false. Additionally, Lua considers any value except nil and false a truthy value. A truthy value in the condition part (if CONDITION then) part of a condition will act like true and run the code in the then section.

Example:

if 0 then
    -- numbers are truthy, so this will always be printed
    print("truthy")
end

If a value is falsey and it’s in an if statement or a function that wants a boolean value, it’s treated like it’s false. This will skip the code after if, and any else code will be run, if present.

Example:

if nil then
    -- this will never be reached
    print("truthy")
else
    -- nil is falsey, so this will always be printed
    print("falsey")
end

The only values that are falsey are false and nil, every other value (numbers, tables, modelparts, etc) is truthy. (nil as a value means there’s no information. It’s literally nothing)

The not operator flips the truthiness of the value into true or false. For example, `not true`, `not 0`, and `not hello` are all false, while `not false` and `not nil` are true.

Examples (all of these are true statements):

not true == false
not false == true
not nil == true -- a non-boolean value is turned into a boolean
not models == false -- models is a modelpart and truthy, so flipping it turns it into false

When used in methods true usually activates something, and false deactivates it. However in some places returning true may turn something off, always read the description of a method, field, or event to discover what boolean does what.