Scripting/Syntaxe/en

De DigiWiki.

Operators

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
() Parentheses a * (b + c)
[] Brackets: list constructor [a, 2, "this", 0.01]
(type) Typecasting message = "The result is:" + (string) result;
 ! ~ ++ -- Logical-NOT, Bitwise-NOT, Increment, Decrement counter++;
* / % Multiply/Dot-Product, Divide, Modulus/Cross-Product rollover = (count + 1)%5;
- Subtraction one = 3 - 2;
+ Addition or joining Strings two = 1+1;

text = "Hello" + "World";

+ Concatenation or joining Lists myList = [1, 2, 3] + [4, 5];

newList = oldList + addList;

<< >> Left Shift, Right Shift eight = 4 << 1;
< <= > >= Less Than, Less Than Or Equal To,

Greater Than, Greater Than or Equal To

isFalse = (6 <= 4);
==  != Comparison Equal, Comparison Not Equal isFalse = ("this" == "that");
& 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 four = 4;

Note: The ++ (increment) and -- (decrement) have their effect on their number either before or after the number is evaluated when used in conditions dependent on whether they are before or after the number.

Outils personnels
  • Cette page a été consultée 755 fois.
donate
Google Ads