Roblox Wiki
Advertisement
Roblox Wiki

In Lua, the boolean data type (also known as bool) only has two values: true and false. true represents data types other than nil while false represents nil, although boolean values (along with every type) cannot be equated (==) with values of different types, which consequently returns false. Both values have their own literals: true and false.

In Roblox, there is a ValueBase subclass for boolean values which is the BoolValue light iconBoolValue dark iconBoolValue class.

In most programming languages, a bit can be treated as a boolean: 0 is treated as false while 1 is treated as true. However, in Lua, 0 as a number is not treated as false, it is instead treated as true.

Operators[]

Lua features three logical operators:

  • The not operator converts a value to its opposite boolean value.
  • The and operator returns its first argument if it is false, otherwise it returns its second argument, and the or operator returns its first argument if it is true, otherwise it returns its second argument.
    • Both and and or operators use short-cut evaluation: the and operator evaluates its second operand only when its first operand is true, while the or operator evaluates its second operand only when its first operand is false.

External links[]


Advertisement