Skip to content
lsl.devlsl.devLSL Dev

Operators

From the wiki’s operators page: “The following table lists the operators in descending order of evaluation, i.e. higher in the table means higher evaluation precedence. Multiple operators on the same line share evaluation precedence. Parenthesize an expression if you need to force an evaluation order.”

OperatorDescriptionUsage example
()parentheses: grouping and evaluation precedenceinteger val = a * (b + c);
[]brackets: list constructorlist lst = [a, 2, "this", 0.01];
(type)typecastingstring message = "The result is:" + (string)result;
! ~ ++ --logical NOT, bitwise NOT, increment, decrementcounter++;
* / %multiply/dot product, divide, modulus/cross productinteger rollover = (count + 1) % 5;
-subtraction, negationinteger one = 3 - 2;
+addition, string concatenationstring text = "Hello" + " world";
+list concatenationlist myList = [1, 2, 3] + [4, 5];
<< >>arithmetic left shift, arithmetic right shiftinteger eight = 4 << 1;
< <= > >=less than, less than or equal to, greater than, greater than or equal tointeger isFalse = (6 <= 4);
== !=comparison: equal, not equalinteger isFalse = ("this" == "that");
&bitwise ANDinteger zero = 4 & 2;
^bitwise XORinteger six = 4 ^ 2;
|bitwise ORinteger six = 4 | 2;
&& ||logical AND, logical ORinteger isFalse = (FALSE && TRUE);
= += -= *= /= %=assignmentinteger eight = four; eight *= 2;
  • “Unlike most other languages that use the C-style && and || operators, both operands are always evaluated.” So if (TRUE || 1/0) llSay(PUBLIC_CHANNEL, "Aha!"); “will cause a Math Error rather than say “Aha!"" (see Errors).
  • “the LSL logical operators || and && have the same precedence”: 1 || 1 && 0 is 0, while 1 | 1 & 0 is 1.
  • “The order of evaluation is from right to left.”
  • “Modulus (%), like division, cause a Script run-time error. Math Error when its second operand equals zero.” and “The % operator only accepts integer (% as modulus) and vector (% as cross product) operands.”
  • “In the LSL implementation, the result always has the same sign as the first operand.”
  • “Equality test on lists does not compare contents, only the length.”

Adapted from the Second Life Wiki page LSL Operators (revision 1216567, 2024-04-30); history, by Second Life Wiki contributors, under CC BY-SA 3.0. Last wiki edit: .