BooleanClass クラスは、2 つの状態のいずれかとなる値の特徴を定義します。
リテラル
true
false
on --true と同じ
off --false と同じ
"true" as booleanClass
"false" as booleanClass
"on" as booleanClass
"off" as booleanClass
演算子
ブール値が
false
の場合は
true
を、ブール値が
true
の場合は
false
を返します。
両方のブール値が
true
の場合は、
true
を返します。
いずれかのブール値が
true
の場合は、
true
を返します。
注:
ブール値
and
および
or
の評価は厳しくありません。最初のブール値の評価で全体の結果が決まる場合があります。
これにより実行時間が節約できるため、略式表記が使えるようになります。たとえば、'
sin a
' を計算する際、変数 '
a
' が
undefined
でない場合は次の例を実行できます。
if a != undefined and sin a > 0 then...
以下のスクリプトでは、BooleanClass クラスのリテラルおよび演算子の使い方を示します。
スクリプト:
|
-- ブール値のテスト ベッド
bool1=true-- 変数をブール値のリテラルに設定します。
bool2=on
if bool1 and bool 2 do print "booleans are equal"-- ブール値を比較します。
-- 「exclusive or」関数を定義します。
-- 入力値のいずれか 1 つだけが ture の場合、
-- true を返します。
fn x or b1 b2 = (not (b1 and b2)) and (b1 or b2)
xor false false-- 入力値の 4 つの組み合わせを xor で評価します。
xor false true
xor true false
xor true true
|
出力:
|
true-- 2 行目の結果
true-- 3 行目の結果
"booleans are equal"-- 4 行目の出力です。
"booleans are equal"-- 4 行目の結果
xor()-- 関数定義
false-- 8 行目の結果です。
true-- 9 行目の結果
true-- 10 行目の結果
|