Operators - KidneyThief/TinScript1.0 GitHub Wiki

TinScript supports most of the same operators that you would normally find in C++. Operator precedence follows the standard convention, however, the use of parenthesis can be used to remove any ambiguity.

Because there are no explicit type casts, mixing types with an operator will perform and convert the operation using the type with the highest resolution.

  • E.g. (3.5f + 4) will return the float value 7.5f.
The following tables describe the available operators, and for each valid type, an example is given. Note: if possible, a value or variable will be converted into the appropriate type before performing the operation.
  • E.g. !"0.0f" == true. "0.0f" has a numerical value of 0, which has a boolean value of false. !false == true.
Many of the binary operators include an assignment variation, which, if specified, is supported.
  • E.g. Using x += 5 is the same as x = x + 5

Table of Contents

Unary Operators

Unary op Description int float bool string object
++ Pre/post increment Coming soon! . . . .
-- Pre/post decrement Coming soon! . . . .
~ Bit invert (ones complement) (~5) is -6 . . . .
! Logical not . . !false (is true)
!true (is false)
. .
- Unary minus (-x) is -1 * x (-x) is -1.0f * x . . .
+ Unary plus (+x) is 1 * x
no effect
(+x) is 1.0f * x
no effect
. . .

Arithmetic Operators

Arithmetic op Assign op Description int float bool string object
+ += Add (3 + 4) is 7 (1.2f + 2.0f) is 3.2f . . .
- -= Subtract (2 - 8) is -6 (5.4f - 1.9f) is 3.5f . . .
* *= Multiply (3 * 4) is 12 (1.5f * 4.2f) is 6.3f . . .
/ /= Divide (12 / 3) is 4 (10.71f / 1.7f) is 6.3f . . .
% %= Modulus (17 % 3) is 2 (15.2f % 2.9f) is 0.7f . . .

Bitwise Operators

Bitwise op Assign op Description int float bool string object
<< <<= Left shift (1 << 8) is 256 . . . .
>> >>= Right shift (28 >> 4) is 7 . . . .
& &= Bitwise AND (9 & 12) is 8
(0b1001 & 0b1100) is 0b1000
. . . .
^ ^= Bitwise exclusive OR (13 ^ 10) is 7
(0b1101 ^ 0b1010) is 0b0111
. . . .
| |= Bitwise inclusive OR (10 | 12) is 14
(0b1010 | 0b1100) is 0b1110
. . . .

Boolean Operators

Boolean op Description int float bool string object
< Less than (3 < 5) is true (3.5f < 2.5f) is false . . .
> Greater than (3 > 5) is false (3.5f > 3.5f) is false . . .
<= Less than or equal to (3 <= 2) is false
(3 <= 3) is true
(3.5f <= 4.5) is true . . .
>= Greater than or equal to (5 >= 3) is true (4.5f >= 5.0f) is false . . .
== Equal to (3 == 3) is true (5.1f == 5.0f) is false (false == false) is true . // if we had:
object obj0 = create CScriptObject();
object obj1 = create CScriptObject();
object obj2 = obj0;


(obj0 == obj1) is false;
(obj0 == obj2) is true;
!= Not equal to (3 != 3) is false (5.1f != 5.0f) is true (true != true) is false . (obj0 != obj1) is true
&& Logical AND . . (true && true) is true
(true && false) is false
. // suppose we execute
destroy obj2;


// then since obj0 no longer exists
(obj0 && obj1) is false
|| Logical OR . . (true || false) is true
(false || false) is false
. // obj1 still exists
(obj0 || obj1) is true
  • Note: As mentioned, using object type values with boolean operators essentially tests if the object(s) exists.
  • Note: There are no operators that deal directly with values of type string. All string values are converted to the appropriate type before being used. For actually manipulating strings, refer to the $$$TZA(add a link to registered string functions) section of this guide.
⚠️ **GitHub.com Fallback** ⚠️