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 might be evaluated to determine the overall result:

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

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

This saves execution time and enables useful shorthand notation. For example, if you want to calculate 'sin a' and if the value of variable 'a' is not undefined , you can 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 bool2 do print "booleans are equal"-- compare the booleans
-- define an "exclusive or" function
-- returns true if only one of the
-- inputs is true
fn xor 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

Comparing / Coercing to Integers

NEW in 3ds Max 2018:BooleanClass values can be compared to Integer values, where 0 is equivalent to false, and all other values are true.

Example:

0 as BooleanClass --> false
1 as BooleanClass --> true
true as Integer --> 1
false as Integer --> 0