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.”
| Operator | Description | Usage example |
|---|---|---|
() | parentheses: grouping and evaluation precedence | integer val = a * (b + c); |
[] | brackets: list constructor | list lst = [a, 2, "this", 0.01]; |
(type) | typecasting | string message = "The result is:" + (string)result; |
! ~ ++ -- | logical NOT, bitwise NOT, increment, decrement | counter++; |
* / % | multiply/dot product, divide, modulus/cross product | integer rollover = (count + 1) % 5; |
- | subtraction, negation | integer one = 3 - 2; |
+ | addition, string concatenation | string text = "Hello" + " world"; |
+ | list concatenation | list myList = [1, 2, 3] + [4, 5]; |
<< >> | arithmetic left shift, arithmetic right shift | integer eight = 4 << 1; |
< <= > >= | less than, less than or equal to, greater than, greater than or equal to | integer isFalse = (6 <= 4); |
== != | comparison: equal, not equal | integer isFalse = ("this" == "that"); |
& | bitwise AND | integer zero = 4 & 2; |
^ | bitwise XOR | integer six = 4 ^ 2; |
| | bitwise OR | integer six = 4 | 2; |
&& || | logical AND, logical OR | integer isFalse = (FALSE && TRUE); |
= += -= *= /= %= | assignment | integer eight = four; eight *= 2; |
Notes from the wiki
Section titled “Notes from the wiki”- “Unlike most other languages that use the C-style
&&and||operators, both operands are always evaluated.” Soif (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 && 0is0, while1 | 1 & 0is1. - “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.”
Reference
Section titled “Reference”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: .