LSL Operators

From InWorldz Wiki
Jump to: navigation, search


Scripting Wiki

InWorldz Functions | LSL Functions | Bot / NPC Functions | Events | Bot Events | Types | Operators | Constants | Flow Control | Glossary

Operators are used to cause an operation (or mathematical action) to be performed on one (such as !) or two operands. The easy and common example is 1 + 2 where 1 and 2 are operands, and the + is the operator.

This concept can be extended much further with LSL since operands can be variables with the special case of the assignment operators requiring that the left hand side be a variable.

Operator Description Usage Example Comments
( ) Parentheses a * ( b + c ) b + c will be evaluated first as it is inside the parentheses.
[ ] Brackets [q, 4, "that", 0.15] Used to enclose a list.
 ! ~ ++ -- Logical-NOT, Bit-wise-NOT, increment, decrement counter++;  !TRUE
* / % Multiply/dot product, divide, modulus/cross-product rollover = (count + 1) % 5 rollover will be the remainder; e.g., if count is 7, then the result is 3. 7 + 1 is 8, 8 divided by 5 is 1 with a remainder of 3.
- Subtraction result = something - 2 Whatever value is stored in something, result will be that amount minus 2
+ Addition, joining strings, concatenating lists result = something + 2
msg = "Hello, " + name
list = [1,2,3] + [4,5]
Whatever value is stored in something, result will be that amount plus 2
If the string variable name is "Bob", msg will be "Hello, Bob"
list will be [1,2,3,4,5]
<< >> Left shift, right shift eight = 4 << 1;
< <= > >= Less than, less than or equal to, greater than, greater than or equal to isFalse = ( 6 <= 4 ) as six is not less than or equal to 4, the equation will return FALSE, which will be stored in the variable isFalse
== != Comparison equal, comparison not equal
if(2 == 4)
{
   // this will never be executed, because 2 will never be equal to 4
}
& Bitwise AND zero = 4 & 2;

four = 4 & 4;

^ Bitwise XOR zero = 4 ^ 4

six = 4 ^ 2;

| Bitwise OR four = 4 | 4;

six = 4 | 2;

|| Logical OR isTrue = ( FALSE || TRUE )
&& Logical AND isFalse = ( FALSE && TRUE )
= += -= *= /= %= Assignment operators four = 4; if another mathematical operation is indicated, that operation is carried out and the result is assigned. Thus, four += 2 will take the current value of four, add 2 to it and save the result in four.

-*-*-* IN PROGRESS *-*-*-