TorqueScript is a typeless scripting language, with similarities in syntax to C/C++. In TorqueScript, you will find that most C/C++ operators work in the familiar way (with important exceptions, as noted here). Besides a subset of C/C++, TorqueScript provides:
- Case-insensitive symbols; keywords false and FALSE are identical.
- Auto creation and destruction of local/global variables and their storage.
- String concatenation, comparison, and auto-string-constant creation.
- Function packaging.
Arithmetic Operators ======== =============== =========== =========== Operator Name Example Explanation ======== =============== =========== =========== *
multiplication $a * $b
Multiply $a
and $b
. /
division $a / $b
Divide $a
by $b
. %
modulo $a % $b
Remainder of $a
divided by $b
. +
addition $a + $b
Add $a
and $b
. -
subtraction $a - $b
Subtract $b
from $a
. ++
auto-increment $a++
Increment $a
.
(post-fix only)
--
auto-decrement $b--
Decrement $b
.
(post-fix only)
.. note: |
|||
Note |
`` is illegal. Th |
e value of `` |
$a++`` is that of the incremented variable: auto-increment is post-fix in syntax, but pre-increment in sematics (the variable is incremented, before the return value is calculated). This behavior is unlike that of C and C++. |
|
`` is illegal. Th |
e value of `` |
$a--`` is that of the decremented variable: auto-decrement is post-fix in syntax, but pre-decrement in sematics (the variable is decremented, before the return value is calculated). This behavior is unlike that of C and C++. |
**Relation | s (Arithmetic, Lo | gical, and St | ring)** |
======== | ================= | ==== ======= | ====== =========== |
Operator | Name |
|
|
======== | ================= | ==== ======= | ====== =========== |
< |
Less than |
|
$b1 if $ais less than $b`` |
> |
More than |
|
$b1 if $ais greater than $b`` |
<= |
Less than or Equa | l to ``$a <= |
|
>= |
More than or Equa | l to ``$a >= |
|
== |
Equal to |
|
|
!= |
Not equal to |
|
|
! |
Logical NOT |
|
|
&& |
Logical AND |
|
|
|| |
Logical OR |
|
|
$= |
String equal to |
|
|
!$= |
|
|
= $d1 if $cnot equal to $d``. |
Bitwise Operators ======== ================== =========== =========== Operator Name Example Explanation ======== ================== =========== =========== ~
Bitwise complement ~$a
flip bits 1 to 0 and 0 to 1 &
Bitwise AND $a & $b
composite of elements where bits in same position are 1 |
Bitwise OR $a | $b
composite of elements where bits 1 in either of the two elements ^
Bitwise XOR $a ^ $b
composite of elements where bits in same position are opposite <<
Left Shift $a << 3
element shifted left by 3 and padded with zeros >>
Right Shift $a >> 3
element shifted right by 3 and padded with zeros ======== ================== =========== ===========
Assignment and Assignment Operators ======== ==================== ============== =========== Operator Name Example Explanation ======== ==================== ============== =========== =
Assignment $a = $b;
Assign value of $b
to $a
Note: the value of an assignment is the value being assigned, so $a = $b = $c is legal. op=
Assignment Operators $a op= $b;
Equivalent to $a = $a op $b
, where op can be any of: * / % + - & | ^ << >> ======== ==================== ============== ===========
String Operators ======== =============== ============= =========== Operator Name Example Explanation ======== =============== ============= =========== @
String $c @ $d
Concatenates strings $c
and $d
into a single string. Numeric literals/variables convert to strings. NL
New Line $c NL $d
Concatenates strings $c
and $d
into a single string separated by new-line. Note: such a string can be decomposed with getRecord() TAB
Tab $c TAB $d
Concatenates strings $c
and $d
into a single string separated by tab. Note: such a string can be decomposed with getField() SPC
Space $c SCP $d
Concatenates strings $c
and $d
into a single string separated by space. Note: such a string can be decomposed with getWord()
The @ symb |
ol will concatena |
te two strings |
|
*Note: Do **Miscella |
not type in OUPUT neous** |
: ___. This is |
|
========= | ====== ====== | ====================== =========== | |
Operator |
|
|
e Explanation |
========= | ====== ====== | ====================== =========== | |
? : |
|
|
y : zEvaluates to yif xequal to 1, else evaluates to z`` |
[] |
|
|
]Synonymous with $a5`` |
|
|
ping
|
etMin(%a, %b) $b)*($c-$d)`` Control associativity in expressions |
|
|
nt |
tion foo() {$a = 1;}`` Required for switch, datablock, new, function |
|
|
|
etMin(%a, %b) |
:: |
|
|
::onCollision()This definition of the onCollision()function is in the Item`` namespace |
|
|
ection |
.field |
// |
|
ent ``// T | his is a comment`` Used to comment out a single line of code |
|
|
nt
|
is is a a ent*/`` |