TorqueScript bridge

The TorqueScript bridge is a way to communicate between JavaScript and TorqueScript. It is purely meant as a compatibility layer.

ts.setVariable(name, value)

This will set a variable within the TorqueScript global scope to value.

Warning

Ensure that the value is coercible to a string/a string!

Arguments:
  • name (string) – The name of the variable to set value to.
  • value (string) – The value of the variable.
ts.getVariable(name)

This will return a variable corresponding to a TorqueScript global variable.

Note

This will ALWAYS return a string, due to how TorqueScript handles internal types.

Arguments:
  • name (string) – The name of the variable to get the value of.
Returns:

A string corresponding to the value held by the variable.

ts.linkClass(name)

Returns a constructor for a TorqueScript class.

Note

Be sure to register any object created by this constructor. If you fail to register an object, no method call will work, as the object has no ID.

Warning

Do not link a datablock class. This will crash the game. I strongly advise AGAINST doing this.

Arguments:
  • name (string) – The name of the class corresponding to a TorqueScript class.
Returns:

A function that works as a constructor for the TorqueScript type specified.

ts.registerObject(object)

Register an object with Torque, allowing for method functions to be called on it, and giving it an object id.

Arguments:
  • object (object) – The object to be registered with Torque.
ts.func(name)

Get a JavaScript function corresponding to the TorqueScript function.

Arguments:
  • name (string) – The name of the function in the global TorqueScript namespace.
Returns:

A JavaScript function that corresponds to the TorqueScript function

ts.obj(name)
ts.obj(id)

Get an object referring to the TorqueScript object given by the name/id

Arguments:
  • id (int) – The ID corresponding to the TorqueScript object.
  • name (string) – The name corresponding to the TorqueScript object.
Returns:

An object referring to the TorqueScript object given by the id/name.

ts.switchToTS()

Change your in-game console to use TorqueScript instead of JavaScript.

ts.expose(info, function)
info.class

The class that the function should be registered to. Optional.

info.name

The name that the function should be registered as.

info.description

The description that the function should have. Optional.

Arguments:
  • info (object) – An object containing all of the attributes listed above.
  • function (function) – A function that should be called every time the TorqueScript callback is called.

Exposes a JavaScript function to TorqueScript.

ts.SimSet.getObject(SimSet, id)

Get an object inside of a SimSet.

Arguments:
  • SimSet (object) – An object referring to a TorqueScript SimSet.
  • id (int) – The integer referring to the object’s position within the SimSet.
Returns:

An object that is found at the index given, inside of the SimSet.

ts.SimSet.getCount(SimSet)

Get the count of all the objects inside the SimSet.

Arguments:
  • SimSet (object) – An object referring to a TorqueScript SimSet.
Returns:

An integer representing the number of objects inside of the SimSet.