TorqueScript Reference

- Main Page
- Related Pages
- Modules
- Classes

Typedefs
Construction Operators
Operators

## Typedefs
typedef type | new

## Detailed Description

## Typedef Documentation

typedef type new

create a new object

Format
  1 %myID = new class([name])
  2 {
  3 [field = value;]
  4 ...
  5 };

Where
  - myID is the return ID that can be used to access the object in the form `%myID.myFunction`.
  - `new` is the keyword telling the engine to create an instance of the following class.
  - class is any class declared in the engine or in script that has been derived from SimObject.
  - name (optional) is the object's name for referencing in the form `name.myFunction` (without % or $ before it).
  - field - You may initialize static or dynamic class fields here, one at a time.

Example
  1 // An SceneObject named 'Truck'
  2 // with two static fields and one dynamic field to define
  3 new SceneObject(Truck)
  4 {
  5 position = "0 0";
  6 size = "5 5";
  7 myField = 100;
  8 };
  9
  10 // A nameless object (tracked by a variable), with no fields to set
  11 %myObject = new SimSet();