TorqueScript Reference
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

◆ Array

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
$userNames[0] = "Heather";
$userNames[1] = "Nikki";
$userNames[2] = "Mich";
echo($userNames[0]);
echo($userNames[1]);
echo($userNames[2]);
void echo(text, [...] *)
Definition output_ScriptBinding.h:36

◆ Boolean

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
$lightsOn = true;
if($lightsOn)
echo("Lights are turned on");

◆ Float

typedef type Float

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

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

◆ Integer

typedef type Integer

Integers are whole numbers.

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

◆ String

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
"abcd"
Example
$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
$a = 'This is a tagged string';
echo(" Tagged string: ", $a);
echo("Detagged string: ", detag('$a'));
String detag(tagID)
Definition taggedStrings_ScriptBinding.h:37
The output will be similar to this:
24
____

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

◆ Vector

typedef type Vector

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

%position = "25 32";
%color = %red SPC %blue SPC %green SPC %alpha;
type SPC
Definition core_ScriptBinding.dox:220

◆ Vector2

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.

◆ Void

typedef type Void

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