UnitSynchronizer - stingray.UnitSynchronizer object reference - Stingray Lua API Reference

stingray.UnitSynchronizer object reference

Description

The UnitSynchronizer is a helper object that synchronizes the creation, destruction, position and rotation of units across multiple networked peers.

It provides a simplified, built-in system for synchronizing the most common modifications to game units, minimizing the number of callbacks that you need to implement in the callback object you use to initialize your Network object. However, if you want more detailed control over the way your units are synchronized, you may want to code your own synchronization instead of using the UnitSynchronizer.

In order to use the UnitSynchronizer, the game objects you synchronize must be configured appropriately in the .network_config data file you use to initialize the Network. See the networking documentation for details.

Functions

Parameters

self :

stingray.UnitSynchronizer

Specifies the object instance that this function will act on.

You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation.

unit :

stingray.Unit

The unit that you want to destroy.

Returns
This function does not return any values.

NOTE: the unit must have been spawned originally by the same UnitSynchronizer object through a call to UnitSynchronizer.spawn_unit().

Parameters

self :

stingray.UnitSynchronizer

Specifies the object instance that this function will act on.

You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation.

id :

integer

The game object ID of the unit to retrieve.

Returns

stingray.Unit

The corresponding unit, if any.

Parameters

self :

stingray.UnitSynchronizer

Specifies the object instance that this function will act on.

You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation.

world :

stingray.World

The game world in which the unit synchronizer should spawn units.

Returns
This function does not return any values.

You must call this function before you can call any other functions of the UnitSynchronizer object.

Parameters

self :

stingray.UnitSynchronizer

Specifies the object instance that this function will act on.

You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation.

type :

string

The type of game object to use for synchronizing this unit, as configured in the .network_config data file.

unit_name :

string

The name of the unit resource that should be spawned.

position :

stingray.Vector3?

The starting position for the new unit. If omitted, the unit will be spawned at the default position (the origin of the 3D coordinate system).

The ? notation indicates that this type is optional: there may be zero or one instances of it.

rotation :

stingray.Quaternion?

The starting rotation for the new unit. If omitted, unit will be spawned with a default rotation.

The ? notation indicates that this type is optional: there may be zero or one instances of it.
Returns

stingray.Unit

The newly created unit.

Parameters

self :

stingray.UnitSynchronizer

Specifies the object instance that this function will act on.

You may use the colon : calling syntax to call this function on an instance of this object. If you do so, you must omit this parameter. For more information, see this Stingray help topic, or this page in the Lua documentation.

unit :

stingray.Unit

The unit whose game object ID will be retrieved.

Returns

integer

The corresponding game object ID, if any.