MAXScript Language Reference > Values > Basic Data Values >

# BooleanClass Values

Value > Basic Data Values > BooleanClass Values

| Values and Collections - Quick Navigation

The BooleanClass class defines the characteristics of values that can only have one of two states.

Literals

    true false on --equivalent to true off --equivalent to false
    "true" as booleanClass
    "false" as booleanClass
    "on" as booleanClass
    "off" as booleanClass

Operators

    not <boolean>

true if boolean= false , false if boolean= true

    <boolean> and <boolean>

true if both boolean values are true

    <boolean> or <boolean>

true if either boolean value is true

Note

The boolean and and or evaluations are non-strict. This means that only the first boolean may be evaluated to determine the overall result:

- If the first operand is false in an and expression, the result must be false, therefore, the second operand is not evaluated.

- If the first operand is true in an or expression, the result must be true , therefore, the second operand is not evaluated.

This saves execution time and enables useful shorthand notation. For example, if you want to calculate 'sin a' if the value of variable 'a' isn’t undefined , you could use the example below:

    if a != undefined and sin a > 0 then...

The following script shows the use of various literals and operators of the BooleanClass class.

SCRIPT:
    -- boolean test bed
    bool1=true-- set variables to boolean literals
    bool2=on
    if bool1 and bool 2 do print "booleans are equal"-- compare the booleans
    -- define an "exclusive or" function
    -- returns true if only one of the
    -- inputs is true
    fn x or b1 b2 = (not (b1 and b2)) and (b1 or b2)
    xor false false-- evaluate 4 combinations of inputs to xor
    xor false true
    xor true false
    xor true true
OUTPUT:
    true-- result of line 2
    true-- result of line 3
    "booleans are equal"-- output from line 4
    "booleans are equal"-- result of line 4
    xor()-- function definition
    false-- result of line 8
    true-- result of line 9
    true-- result of line 10