In computer science, a boolean data type has two
values (usually denoted true and false), to indicate whether
whatever it is evaluating is true or not. For instance, the expression
(1 > 2) evaluates to the boolean value false.
Boolean values are especially useful in their use with
if statements, which allow you to conditionally execute
a piece of code only if the expression being evaluated is true, and
(optionally) conditionally execute another piece of code if the
expression is false.
In EDL and C++, boolean values may be efficiently stored in the bool
data type.
Alternatively, due to their numerical representation, they may also be
stored in any other numeric data type, such as int, or GM's
traditional variant data type, var (implied when no data type is
specified). These storage methods are generally less efficient for a
boolean value.
Attempting to store a boolean in a string will result in an error.
Instead, you should use the string function to
convert it first.
bool a = (2 > 1); //true
int b = (2 > 1); //true, or 1
var c = (2 > 1); //1.0
d = (2 > 1); //same as above (var)
string e = string(2 > 1); //"1"
In GM and ENIGMA, the constants true and
false are numerically defined for you:
Meaning that you can use true and 1 interchangeably, and likewise with
false and 0.
In GM and ENIGMA, other values may evaluate as true or false, especially
when used in an if statement.
Generally, you should avoid evaluating strings and non-numeric values
(or even non-boolean values, for that matter) as boolean. Instead, you
should use the appropriate operators (== and !=)
and string-handling functions (and
comparison operators, such as \< and >=, for numeric values). For
example, the following script could be used to convert "", "0", and
"false" into false, and any other string value into true:
if (isreal(argument0)) return argument0;
return (argument0 != "" and argument0 != "0" and argument0 != "false");