TorqueScript Reference

- Main Page
- Related Pages
- Modules
- Classes

Typedefs
Data Types

## Typedefs
typedef type | Array
typedef type | Boolean
typedef type | Float
typedef type | Integer
typedef type | String
typedef type | Vector
typedef type | Vector2
typedef type | Void

## Detailed Description

## Typedef Documentation

typedef type Array

Arrays are data structures used to store consecutive values of the same data type.

- $TestArray[n] (Single-dimension)
- $TestArray[m,n] (Multidimensional)
- $TestArray[m_n] (Multidimensional)

Example
  1 $userNames[0] = "Heather";
  2 $userNames[1] = "Nikki";
  3 $userNames[2] = "Mich";
  4 echo($userNames[0]);
  5 echo($userNames[1]);
  6 echo($userNames[2]);

typedef type Boolean

Boolean "numbers" have only two values - true or false.

true (1) false (0)

The constant `true` evaluates to the number 1 in TorqueScript, and the constant `false` evaluates to the number 0. However, non-zero values are also considered true. Think of booleans as "on/off" switches, often used in conditional statements.

Example
  1 $lightsOn = true;
  2
  3 if($lightsOn)
  4 echo("Lights are turned on");

typedef type Float

Float, is a floating point number which can hold decimal values.

1 1.234
2 1234e-3 // you can use scientific notion

typedef type Integer

Integers are whole numbers.

1 123
2 0xc001 // you can use 0x followed by hexadecimal digits

typedef type String

Text, such as names or phrases, are supported as strings.

Numbers can also be stored in String format. Standard strings are stored in double-quotes.

Example
  1 "abcd"

Example
  1 $UserName = "Heather";

Tagged strings are special in that they contain string data, but also have a special numeric tag associated with them. Tagged strings are used for sending string data across a network. The value of a tagged string is only sent once, regardless of how many times you actually do the sending.

On subsequent sends, only the tag value is sent. Tagged values must be de-tagged when printing. You will not need to use a tagged string often unless you are in need of sending strings across a network often, like a chat system.

Example
  1 $a = 'This is a tagged string';
  2 echo(" Tagged string: ", $a);
  3 echo("Detagged string: ", detag('$a'));
  The output will be similar to this:
  1 24
  2 ____

The second echo will be blank unless the string has been passed to you over a network.

typedef type Vector

Vector is a String of any number of values separated by spaces between each.

1 %position = "25 32";
2 %color = %red SPC %blue SPC %green SPC %alpha;

typedef type Vector2

Vector2 is a String of two numbers (Float or Integer) separated by a space.

It is a special case of a Vector. Note that TorqueScript does not check that you have exactly two elements. The type Vector2 is used here to remind you what is expected by a function, for instance.

typedef type Void

Void is actually not a real type. It simply represents the absense of a type.