$nav
===== Boolean =====
LSL does not support a boolean type per se; instead, its function is performed by an $lty[integer]. When a variable or parameter is a boolean, it means that it's an integer which represents a truth value of //false// when it is zero, or //true// when it is not zero.
Note that the constant $lct[TRUE] has the value 1, but //any// value different to 0 (including negatives) will serve as a truth value of //true// for variables that represent a boolean value.
It is not recommended to test boolean values against $lct[TRUE] or $lct[FALSE]. In most cases, that's not necessary. When the variables are properly named, they usually can be better read by omitting such comparisons. Consider the following example:
integer flag = FALSE;
default
{
touch_start(integer n)
{
flag = !flag; // flip the flag
if (flag == TRUE)
{
llTargetOmega(<0, 0, 1>, PI, 1);
}
else if (flag == FALSE)
{
llTargetOmega(<0, 0, 0>, 0, 0);
}
}
}
And now compare it with this version:
integer rotating;
default
{
touch_start(integer n)
{
rotating = !rotating; // flip the rotating status
if (rotating)
{
llTargetOmega(<0, 0, 1>, PI, 1);
}
else
{
llTargetOmega(<0, 0, 0>, 0, 0);
}
}
}
The latter version is more compact, more readable, faster, and uses less memory. In short, it's better in all respects. It works, because when the argument to an $lkw[/if] statement is an integer, any value distinct to 0 will be taken as true. The trick for readability is to decide the name of the variable depending on what it represents when the truth value is //true//; in the latter example, when the variable is true it will represent that the object is rotating, thus the choice ''rotating'' for the variable name.
==== See also ====
* $lty[integer] type
* $lkw[if] statement