<table border="0" cellpadding="0" cellspacing="0" width="700">
<tbody>
<tr>
<td width="700"><table id="toc" summary="Contents">
<tbody>
<tr>
<td><div id="toctitle">
<h2>Contents</h2>
<ul>
<li class="toclevel-1"><a href="#Language_Features"><span class="tocnumber">1</span> <span class="toctext">Language Features</span></a></li>
<li class="toclevel-1"><a href="#Variable_Names"><span class="tocnumber">2</span> <span class="toctext">Variable Names</span></a></li>
<li class="toclevel-1"><a href="#Constants"><span class="tocnumber">3</span> <span class="toctext">Constants</span></a></li>
<li class="toclevel-1"><a href="#Operators"><span class="tocnumber">4</span> <span class="toctext">Operators</span></a></li>
<li class="toclevel-1"><a href="#Keywords"><span class="tocnumber">5</span> <span class="toctext">Keywords</span></a>
<ul>
<li class="toclevel-2"><a href="#break"><span class="tocnumber">5.1</span> <span class="toctext">break</span></a></li>
<li class="toclevel-2"><a href="#case"><span class="tocnumber">5.2</span> <span class="toctext">case</span></a></li>
<li class="toclevel-2"><a href="#continue"><span class="tocnumber">5.3</span> <span class="toctext">continue</span></a></li>
<li class="toclevel-2"><a href="#datablock"><span class="tocnumber">5.4</span> <span class="toctext">datablock</span></a></li>
<li class="toclevel-2"><a href="#default"><span class="tocnumber">5.5</span> <span class="toctext">default</span></a></li>
<li class="toclevel-2"><a href="#else"><span class="tocnumber">5.6</span> <span class="toctext">else</span></a></li>
<li class="toclevel-2"><a href="#FALSE"><span class="tocnumber">5.7</span> <span class="toctext">FALSE</span></a></li>
<li class="toclevel-2"><a href="#for"><span class="tocnumber">5.8</span> <span class="toctext">for</span></a></li>
<li class="toclevel-2"><a href="#function"><span class="tocnumber">5.9</span> <span class="toctext">function</span></a></li>
<li class="toclevel-2"><a href="#if"><span class="tocnumber">5.10</span> <span class="toctext">if</span></a></li>
<li class="toclevel-2"><a href="#new"><span class="tocnumber">5.11</span> <span class="toctext">new</span></a></li>
<li class="toclevel-2"><a href="#package"><span class="tocnumber">5.12</span> <span class="toctext">package</span></a></li>
<li class="toclevel-2"><a href="#parent"><span class="tocnumber">5.13</span> <span class="toctext">parent</span></a></li>
<li class="toclevel-2"><a href="#return"><span class="tocnumber">5.14</span> <span class="toctext">return</span></a></li>
<li class="toclevel-2"><a href="#switch"><span class="tocnumber">5.15</span> <span class="toctext">switch</span></a></li>
<li class="toclevel-2"><a href="#switch.24"><span class="tocnumber">5.16</span> <span class="toctext">switch$</span></a></li>
<li class="toclevel-2"><a href="#TRUE"><span class="tocnumber">5.17</span> <span class="toctext">TRUE</span></a></li>
<li class="toclevel-2"><a href="#while"><span class="tocnumber">5.18</span> <span class="toctext">while</span></a></li>
</ul>
</li>
</ul></td>
</tr>
</tbody>
</table>
<p> </p>
<p><strong>IMPORTANT:</strong> You can download and view the Full TorqueScript Manual by clicking here: <a href="../Torque 3D - Script Manual.chm" class="downloads">TorqueScript Reference Manual</a></p><br />
<p><strong>Note for Windows Users:</strong> Due to security measures, the OS may block the CHM after you download it. To unblock it, perform the following steps:<br /></p>
<p>1. Locate CHM on your hard drive<br />
2. Right click on the CHM, then click Properties<br />
3. At the bottom, click the "Unblock" button<br />
4. Apply and close the properties<br /><br /></p>
<strong>Note for OSX Users:</strong> There is no default CHM viewer installed with Mac OSX. There are several free options available for download:<br />
<ul><li><a href="http://chmox.sourceforge.net/" class="external">Chmox</a></li>
<li><a href="http://www.robinlu.com/blog/ichm" class="external">iChm</a></li>
</ul>
<br />
<p><a name="Language_Features" id="Language_Features"></a>
</p>
<h2> <span class="mw-headline">Language Features</span></h2>
<p>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: </p>
<ul>
<li>Case-insensitive symbols; keywords <i>false</i> and <i>FALSE</i> are identical. </li>
<li>Auto creation and destruction of local/global variables and their storage. </li>
<li>String concatenation, comparison, and auto-string-constant creation. </li>
<li>Function packaging. </li>
</ul><br />
<a name="Variable_Names" id="Variable_Names"></a>
<h2> <span class="mw-headline">Variable Names</span></h2></td>
</tr>
</tbody>
</table>
<table bgcolor="#eeeeee" border="1" cellpadding="4" cellspacing="0" width="700">
<tbody>
<tr>
<th bgcolor="#6699ff" width="10%"><b>Type</b></th>
<th width="10%"><b>Syntax</b></th>
<th><b>Example</b></th>
<th><b>Explanation</b></th>
</tr>
<tr>
<td bgcolor="#6699ff"><b>
Global
</b></td>
<td>
prefix $
</td>
<td>
$a
</td>
<td>
$a is a global variable
</td>
</tr>
<tr>
<td bgcolor="#6699ff"><b>
Local
</b></td>
<td>
prefix %
</td>
<td>
%b
</td>
<td>
%b is a local variable
</td>
</tr>
<tr>
<td rowspan="3" bgcolor="#6699ff" valign="top"><b>Array</b><br />
(Global<br />
or Local)
</td>
<td rowspan="2" bgcolor="#eeeeee" valign="top">
postfix []
</td>
<td>
$MyArray[n]
</td>
<td>
Array
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
$MyMultiArray[n,m]
$MyMultiArrayn_m
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
Multi-dimensional array
</td>
</tr>
<tr>
<td colspan="3" bgcolor="#eeeeee"><p><b>Note:</b> TorqueScript does not have support for arrays as such.
Instead, the bracket notation is a shorthand for creating a variable
name. $a[0] is synonymous with $a0, and $M[1,4] with $M1_4. You must
not think of $a as the name of the array containing $a[5]. TorqueScript
arrays provide the means for creating variable names dynamically: if $i
is 5, then $a[$i] is synonymous with $a5. </p></td>
</tr>
</tbody>
</table><br />
<table border="0" cellpadding="0" cellspacing="0" width="700">
<tbody>
<tr>
<td width="700"><a name="Constants" id="Constants"></a>
<h2> <span class="mw-headline">Constants</span></h2></td>
</tr>
</tbody>
</table>
<table bgcolor="#eeeeee" border="1" cellpadding="4" cellspacing="0" width="700">
<tbody>
<tr>
<th bgcolor="#6699ff" width="10%"><b>Type</b></th>
<th bgcolor="#eeeeee" width="20%"><b>Example</b></th>
<th bgcolor="#eeeeee"><b>Explanation</b></th>
</tr>
<tr>
<td rowspan="2" bgcolor="#6699ff" valign="top"><b>
Boolean
</b></td>
<td>
TRUE
</td>
<td>
1
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
FALSE
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
0
</td>
</tr>
<tr>
<td rowspan="2" bgcolor="#6699ff" valign="top"><b>
Integer
</b></td>
<td>
123
</td>
<td>
decimal
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
0xabc
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
hexadecimal
</td>
</tr>
<tr>
<td rowspan="3" bgcolor="#6699ff" valign="top"><b>
Float
</b></td>
<td align="left" bgcolor="#eeeeee" valign="top">
1.23
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
floating-point
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
1.00E-003
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
scientific notation
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#eeeeee"><b>Note</b>: If the float is less
than 1, explicitly include the leading "0" before the ".", e.g., "0.2".
Entering ".2" will not work in every circumstance.</td>
</tr>
<tr>
<td rowspan="10" bgcolor="#6699ff" valign="top"><b>
Character
</b></td>
<td>
\n
</td>
<td>
newline
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\r
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
carriage return
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\t
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
tab
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\c0 .. \c9
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
colorize subsequent console output
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\cr
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
reset to default color
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\cp
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
push color from color stack
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\co
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
pop color from color stack
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\xhh
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
two-digit hex value ASCII code
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\\
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
backslash
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
\"
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
double-quotes
</td>
</tr>
<tr>
<td rowspan="2" bgcolor="#6699ff" valign="top"><b>
String
</b></td>
<td>
"Hello world"
</td>
<td>
Normal string
</td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top">
'Torque Rocks'
</td>
<td align="left" bgcolor="#eeeeee" valign="top">
A tagged
string, as used in communication between client and server. The value
of a tagged string is sent only once; subsequently, only the tag is
sent. Clients will store the string at an index identified by the tag
and can look up the value, avoiding the need for it to be sent
repeatedly.
</td>
</tr>
<tr>
<td rowspan="2" bgcolor="#6699ff" valign="top"><b>
Vector
</b></td>
<td>
"1.0 2.0 1.0 2.0"
</td>
<td>
4-element vector
</td>
</tr>
<tr>
<td colspan="2" bgcolor="#eeeeee"><p><b>Note:</b> TorqueScript does not have support for vectors as such.
The vector exemplified here is simply a space-separated string. Space-,
tab-, and newline-separated strings crop up in the calling sequence of
certain functions, notably in the return value, which technically is a
scalar, but may be a string that can be interpreted as a vector. </p></td>
</tr>
</tbody>
</table><br />
<table border="0" cellpadding="0" cellspacing="0" width="700">
<tbody>
<tr>
<td width="700"><a name="Operators" id="Operators"></a>
<h2> <span class="mw-headline">Operators</span></h2></td>
</tr>
</tbody>
</table>
<table bgcolor="#eeeeee" border="1" cellpadding="4" cellspacing="0" width="700">
<tbody>
<tr>
<th bgcolor="#eeeeee" width="15%"><b>
Operator
</b></th>
<th bgcolor="#eeeeee" width="20%"><b>
Name
</b></th>
<th bgcolor="#eeeeee" width="20%"><b>
Example
</b></th>
<th bgcolor="#eeeeee" width="45%"><b>
Explanation
</b></th>
</tr>
<tr>
<td colspan="4" bgcolor="#6699ff"><b>Arithmetic Operators</b>
</td>
</tr>
<tr>
<td>
*
</td>
<td>
multiplication
</td>
<td>
$a * $b
</td>
<td>
Multiply $a and $b.
</td>
</tr>
<tr>
<td>
/
</td>
<td>
division
</td>
<td>
$a / $b
</td>
<td>
Divide $a by $b.
</td>
</tr>
<tr>
<td>
%
</td>
<td>
modulo
</td>
<td>
$a % $b
</td>
<td>
Remainder of $a divided by $b.
</td>
</tr>
<tr>
<td>
+
</td>
<td>
addition
</td>
<td>
$a + $b
</td>
<td>
Add $a and $b.
</td>
</tr>
<tr>
<td>
-
</td>
<td>
subtraction
</td>
<td>
$a - $b
</td>
<td>
Subtract $b from $a.
</td>
</tr>
<tr>
<td>
++
</td>
<td>
auto-increment<br />
(post-fix only)
</td>
<td>
$a++
</td>
<td>
Increment $a. Note: ++$a is illegal.
<b>Note:</b> the value of $a++ is that of the incremented variable: auto-increment
is post-fix in syntax, but pre-increment in semantics (the variable is
incremented, <i>before</i> the return value is calculated). This behavior is unlike that of C and C++.
</td>
</tr>
<tr>
<td>
- -
</td>
<td>
auto-decrement<br />
(post-fix only)
</td>
<td>
$b--
</td>
<td>
Decrement $b. Note: --$b is illegal.
<b>Note:</b> the value of $a-- is that of the decremented variable: auto-decrement
is post-fix in syntax, but pre-decrement in semantics (the variable is
decremented, <i>before</i> the return value is calculated). This behavior is unlike that of C and C++.
</td>
</tr>
<tr>
<td colspan="4" bgcolor="#6699ff"><b>Relations (Arithmetic, Logical, and String)</b>
</td>
</tr>
<tr>
<td>
<
</td>
<td>
Less than
</td>
<td>
$a < $b
</td>
<td>
1 if $a is less than % b (0 otherwise.)
</td>
</tr>
<tr>
<td>
>
</td>
<td>
More than
</td>
<td>
$a > $b
</td>
<td>
1 if $a is greater than % b (0 otherwise.)
</td>
</tr>
<tr>
<td>
<=
</td>
<td>
Less than or Equal to
</td>
<td>
$a <= $b
</td>
<td>
1 if $a is less than or equal to % b (0 otherwise.)
</td>
</tr>
<tr>
<td>
>=
</td>
<td>
More than or Equal to
</td>
<td>
$a >= $b
</td>
<td>
1 if $a is greater than or equal to % b (0 otherwise.)
</td>
</tr>
<tr>
<td>
==
</td>
<td>
Equal to
</td>
<td>
$a == $b
</td>
<td>
1 if $a is equal to % b (0 otherwise.)
</td>
</tr>
<tr>
<td>
!=
</td>
<td>
Not equal to
</td>
<td>
$a != $b
</td>
<td>
1 if $a is not equal to % b (0 otherwise.)
</td>
</tr>
<tr>
<td>
!
</td>
<td>
Logical NOT
</td>
<td>
!$a
</td>
<td>
1 if $a is 0 (0 otherwise.)
</td>
</tr>
<tr>
<td>
&&
</td>
<td>
Logical AND
</td>
<td>
$a && $b
</td>
<td>
1 if $a and $b are both non-zero (0 otherwise.)
</td>
</tr>
<tr>
<td>
||
</td>
<td>
Logical OR
</td>
<td>
$a || $b
</td>
<td>
1 if either $a or $b is non-zero (0 otherwise.)
</td>
</tr>
<tr>
<td>
$=
</td>
<td>
String equal to
</td>
<td>
$c $= $d
</td>
<td>
1 if $c equal to $d .
</td>
</tr>
<tr>
<td>
!$=
</td>
<td>
String not equal to
</td>
<td>
$c !$= $d
</td>
<td>
1 if $c not equal to $d.
</td>
</tr>
<tr>
<td colspan="4" bgcolor="#6699ff"><b>Bitwise Operators</b>
</td>
</tr>
<tr>
<td>
~
</td>
<td>
Bitwise complement
</td>
<td>
~$a
</td>
<td>
flip bits 1 to 0 and 0 to 1. (i.e. ~10b == 01b)
</td>
</tr>
<tr>
<td>
&
</td>
<td>
Bitwise AND
</td>
<td>
$a & $b
</td>
<td>
composite of elements where bits in same position are 1. (i.e. 1b & 1b == 1b)
</td>
</tr>
<tr>
<td>
|
</td>
<td>
Bitwise OR
</td>
<td>
$a | $b
</td>
<td>
composite of elements where bits 1 in either of the two elements. (i.e. 100b & 001b == 101b)
</td>
</tr>
<tr>
<td>
^
</td>
<td>
Bitwise XOR
</td>
<td>
$a ^ $b
</td>
<td>
composite of elements where bits in same position are opposite. (i.e. 100b & 101b == 001b)
</td>
</tr>
<tr>
<td>
<<
</td>
<td>
Left Shift
</td>
<td>
$a << 3
</td>
<td>
element shifted left by 3 and padded with zeros. (i.e. 11b << 3d == 11000b)
</td>
</tr>
<tr>
<td>
>>
</td>
<td>
Right Shift
</td>
<td>
$a >> 3
</td>
<td>
element shifted right by 3 and padded with zeros. (i.e. 11010b >> 3d == 00011b)
</td>
</tr>
<tr>
<td colspan="4" bgcolor="#6699ff"><b>Assignment and Assignment Operators</b>
</td>
</tr>
<tr>
<td>
=
</td>
<td>
Assignment
</td>
<td>
$a = $b;
</td>
<td>
Assign value of $b to $a.
<b>Note</b>: the value of an assignment is the value being assigned, so $a = $b = $c is legal.
</td>
</tr>
<tr>
<td>
op=
</td>
<td>
Assignment Operators
</td>
<td>
$a <i>op</i>= $b;
</td>
<td>
Equivalent to $a = $a <i>op</i> $b, where <i>op</i> can be any of:<br />
* / % + - & | ^ << >>
</td>
</tr>
<tr>
<td colspan="4" bgcolor="#6699ff"><b>String Operators</b>
</td>
</tr>
<tr>
<td>
@
</td>
<td>
String concatenation
</td>
<td>
$c @ $d
</td>
<td>
Concatenates strings $c and $d into a single string. Numeric literals/variables convert to strings.
</td>
</tr>
<tr>
<td>
NL
</td>
<td>
New Line
</td>
<td>
$c NL $d
</td>
<td>
Concatenates strings $c and $d into a single string separated by new-line.
<b>Note</b>: such a string can be decomposed with getRecord()
</td>
</tr>
<tr>
<td>
TAB
</td>
<td>
Tab
</td>
<td>
$c TAB $d
</td>
<td>
Concatenates strings $c and $d into a single string separated by tab.
<b>Note</b>: such a string can be decomposed with getField()
</td>
</tr>
<tr>
<td>
SPC
</td>
<td>
Space
</td>
<td>
$c SPC $d
</td>
<td>
Concatenates strings $c and $d into a single string separated by space.
<b>Note</b>: such a string can be decomposed with getWord()
</td>
</tr>
<tr>
<td colspan="4" bgcolor="#6699ff"><b>Miscellaneous</b>
</td>
</tr>
<tr>
<td>
? :
</td>
<td>
Conditional
</td>
<td>
x ? y : z
</td>
<td>
Evaluates to y if x equal to 1, else evaluates to z.
</td>
</tr>
<tr>
<td>
[]
</td>
<td>
Array element
</td>
<td>
$a[5]
</td>
<td>
Synonymous with $a5.
</td>
</tr>
<tr>
<td>
( )
</td>
<td>
Delimiting,<br />
<br />
Grouping
</td>
<td>
t2dGetMin(%a, %b)<br />
if ( $a == $b )<br />
($a+$b)*($c-$d)
</td>
<td>
Argument list for function call
Used with <i>if</i>, <i>for</i>, <i>while</i>, <i>switch</i> keywords.
Control associatively in expressions
</td>
</tr>
<tr>
<td>
{}
</td>
<td>
Compound statement<br />
(Block)
</td>
<td>
if (1) {$a = 1; $b = 2;}
function foo() {$a = 1;}
</td>
<td>
Delimit multiple statements
optional for <i>if</i>, <i>else</i>, <i>for</i>, <i>while</i>
Required for <i>switch</i>, <i>datablock</i>, <i>new</i>, <i>function</i>
</td>
</tr>
<tr>
<td>
,
</td>
<td>
Listing
</td>
<td>
t2dGetMin(%a, %b)<br />
%M[1,2]
</td>
<td>
Delimiter for arguments
<b>Note</b>: there is no "comma operator", as defined in C/C++; $a = 1, $b = 2; is a parse error
</td>
</tr>
<tr>
<td>
::
</td>
<td>
Namespace
</td>
<td>
Item::onCollision()
</td>
<td>
This definition of the onCollision() function is in the Item namespace.
</td>
</tr>
<tr>
<td>
.
</td>
<td>
Field/Method selection
</td>
<td>
%obj.field <br />
%obj.method()
</td>
<td>
Select a console method or field
</td>
</tr>
<tr>
<td>
//
</td>
<td>
Single-line comment
</td>
<td>
// This is a comment
</td>
<td>
Used to comment out a single line of code.
</td>
</tr>
<tr>
<td>
/* */
</td>
<td>
Multi-line comment
</td>
<td>
/*This is a a<br />
multi-line<br />
comment*/<br />
</td>
<td>
Used to comment out multiple consecutive lines.<br />
/* opens the comment, and */ closes it.
</td>
</tr>
</tbody>
</table><br /><br />
<table border="0" cellpadding="0" cellspacing="0" width="700">
<tbody>
<tr>
<td width="700"><a name="Keywords" id="Keywords"></a>
<h2> <span class="mw-headline">Keywords</span></h2>
<p><b>Note:</b> Although keywords are not reserved, it is considered bad practice to use variables that have the same spelling as a keyword. </p><br /></td>
</tr>
</tbody>
</table>
<table border="1" cellpadding="0" cellspacing="0" width="700">
<tbody>
<tr>
<td bgcolor="#6699ff" width="700"><b> <a name="break" id="break"></a>
<h3> <span class="mw-headline">break</span></h3>
</b></td>
</tr>
<tr>
<td align="left" bgcolor="#eeeeee" valign="top" width="700"><p><b>Purpose</b> Use <i>break</i> to exit the innermost while loop.
Unlike C and C++, <i>break</i> has no effect in a switch or switch$ statement.<br />
</p>
<pre>%count = 0;