BooleanClass Values

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

Notes

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

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 ..

Examples

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

false -- result of line 11