BooleanClass クラスは、2 つの状態のいずれかとなる値の特徴を定義します。
リテラル
true
false
on --equivalent to true
off --equivalent to false
"true" as booleanClass
"false" as booleanClass
"on" as booleanClass
"off" as booleanClass
演算子
not <boolean>
boolean= false
の場合は true
、boolean= true
の場合は false
<boolean> and <boolean>
両方のブール値が true
の場合は true
<boolean> or <boolean>
いずれかのブール値が true
の場合は true
ブール値 and
および or
の評価は厳しくありません。最初のブール値の評価で全体の結果が決まる場合があります。
最初のオペランドが and
式において false
である場合、結果は false にmust
。このため、2 番目のオペランドは評価されません。
最初のオペランドが or
式において true
である場合、結果は true
になります。このため、2 番目のオペランドは評価されません。
これにより実行時間が節約できるため、略式表記が使えるようになります。たとえば、'sin a'
を計算する際、変数 'a'
が undefined
でない場合は次の例を実行できます。
if a != undefined and sin a > 0 then...
以下のスクリプトでは、BooleanClass クラスのリテラルおよび演算子の使い方を示します。
スクリプト:
-- 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
出力:
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
整数との比較/強制的な置き換え
3ds Max 2018 以降で使用可能: BooleanClass
値を Integer
値と比較できます。0 は false に、それ以外のすべての値は true に対応します。
例:
0 as BooleanClass --> false 1 as BooleanClass --> true true as Integer --> 1 false as Integer --> 0