Skip to content

Latest commit

 

History

History
201 lines (147 loc) · 8.28 KB

referenceguide.rst

File metadata and controls

201 lines (147 loc) · 8.28 KB

Quick Reference - TODO

Language Features

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.

Variable Names

Constants

Operators

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:

``++$a

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++.

``--$b

`` 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

Example

Explanation

======== ================= ==== ======= ====== ===========
< Less than

``$a <

$b1 if$ais less than$b``
> More than

``$a >

$b1 if$ais greater than$b``
<= Less than or Equa l to ``$a <=

$b1 if$ais less than or equal to$b``

>= More than or Equa l to ``$a >=

$b1 if$ais greater than or equal to$b``

== Equal to

``$a ==

$b1 if$ais equal to$b``

!= Not equal to

``$a !=

$b1 if$ais not equal to$b``

! Logical NOT

!$a

1 if $a is 0

&& Logical AND

``$a &&

$b1 if$aand$b`` are both non-zero

|| Logical OR

``$a ||

$b1 if either$aor$b`` is non-zero

$= String equal to

``$c $=

$d1 if$cequal to$d``.

!$=

String not equal

to ``$c !$

= $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

together exactly how you specify, without adding any additional whitespace:

*Note: Do

**Miscella

not type in OUPUT

neous**

: ___. This is

placed in the sample code to show you what the console would display.*

=========

====== ====== ====================== ===========
Operator

Name

Exampl

e Explanation
=========

====== ====== ====================== ===========
? :

Conditional

``x ?

y : zEvaluates toyifxequal to 1, else evaluates toz``
[]

Array element

``$a[5

]Synonymous with$a5``

( )

Delimiting, Grou

ping t2dGif (

``($a+

etMin(%a, %b)Argument list for function call $a == $b ) Used with if, for, while, switch keywords

$b)*($c-$d)`` Control associativity in expressions

{}

Compound stateme

nt if (func

  1. {$a = 1; $b = 2;}`` Delimit multiple statements, optional for if, else, for, while

tion foo() {$a = 1;}`` Required for switch, datablock, new, function

,

Listing

t2dG%M[1

etMin(%a, %b)Delimiter for arguments. **Note:** there is no "comma operator", as defined in C/C++; $a = 1, $b = 2; is a parse error ,2]

::

Namespace

``Item

::onCollision()This definition of theonCollision()function is in theItem`` namespace

.

Field/Method sel

ection %obj%obj

.fieldSelect a console method or field .method()

//

Single-line comm

ent ``// T his is a comment`` Used to comment out a single line of code

/* */

Multi-line comme

nt /*Thmult

``comm

is is a aUsed to comment out multiple consecutive lines i-line /* opens the comment, and */ closes it

ent*/``

Keywords

break

case

continue

datablock

default

else

FALSE

for

function

if

new

package

parent

return

switch

switch$

TRUE

while