A B C D E F G I J K L M N O R S T U V W

Boolean operators behave like other operators such as +, -, *, / etc except the inputs and output can only take on two values. These values can be represented as TRUE and FALSE or 1 and 0 although any non zero value will generally be treated as TRUE.

Unlike most modern programming languages with optimizing compilers, the boolean operators in LSL do not short-circuit. In C, for example, when using ||, if the condition on the left turns out to be true, the computer does not even evaluate the condition on the right; there is no need because we can already tell that the || will return TRUE. Similar logic works for &&: if the first condition is false, there is no need to evaluate the other condition because the && must return FALSE. This leads to speedups in complicated conditionals.

LSL does not do this, so if you’re expecting it, it may make your code less efficient, or worse yet, incorrect if you’re expecting a function in the second half of an || or && not to be called.

Also, unlike the most programming languages, LSL evaluates conditions right to left, so in (getVar1() && getVar2()) function getVar2() is run before getVar1().

Boolean Operators

Note: Operators that expect boolean values from integers (TRUE or FALSE) will treat all non-zero values as TRUE.

Operator Name Syntax Description
&& AND var1 && var2 Returns TRUE if var1 and var2 are both TRUE, FALSE otherwise.
var1 and var2 must both be integers.
|| OR var1 || var2 Returns TRUE if either var1 or var2 are TRUE, FALSE otherwise.
var1 and var2 must both be integers.
! NOT !var1 Returns TRUE if var1 is FALSE, or FALSE if var1 is TRUE. var1 must be an integer.

Note:

  • When using == or != on lists, it’s important to remember that only the list lengths are compared. So ["a"] == ["b"] would return TRUE, the same as llGetListLength(["a"]) == llGetListLength(["b"]).
  • Do not confuse the assignment operator “=” with the equality operator “==”! When comparing two values, use “==”. When assigning a value, use “=”. The compiler will not catch your error, as it’s possible to assign values within an IF statement delibeartely. Compiling a script with “=” rather than “==” will probably cause the statement to evaluate to TRUE and the conditional variable to become corrupted.
  • Unlike most languages, in LSL the || operator takes precedence over the && operator. Thus, this expression: (TRUE && TRUE || FALSE && FALSE) will evaluate as FALSE, as it is reduced to (TRUE && TRUE && FALSE).

These operators are often used in conditional statements.

Q: How do you have a boolean XOR?
A: Use an if() statement:
if((1 || 0) && !(1 && 0)) //if((they are either T or F) AND NOT(T and F))

Credit to: Lslwiki.net (not working) with changes made for brevity and clarity.