Class Router
From TrainzOnline
- API Hierarchy
- Router
- The Router class handles the transmission of messages between game objects and contains methods to provide references to specific objects given their name or Id.
Contents |
Constants
public define int MESSAGE_BROADCAST = 0 | The message will be sent to all objects in the Router |
GetGameObject
public native GameObject GetGameObject(string uniqueName)
public native GameObject GetGameObject(int uniqueId)
public native GameObject GetGameObject(int uniqueId)
- Parameters
- uniqueName = Name of object as assigned in Surveyor.
- uniqueId = Id of object as assigned by the Router for each session.
- Returned Value
- A reference to the GameObject described, null if no such object exists.
- Syntax
GameObject go = Router.GetGameObject(vehicle.GetName());
- Notes
- The objects name will normally be its username with a unique serial added by the game when the object is placed.
- This name can be edited by the user.
- Remember that not all objects will be named.
- Although Surveyor issues a warning on any attempt to name an object using a name which already exists, no restriction is actually enforced.
- As a result it is possible that a name will not be unique.
- Reference to an object's Id on the other hand is guaranteed to be unique for the current session.
- Ids are not preserved between sessions.
Info
public native void Router.Info(void)
- Parameters
- None
- Returned Value
- None
- Syntax
Router.Info();
- Notes
- Logs current Router information to jetlog.txt.
- Used for debugging a session.
PostMessage
public obsolete native void PostMessage(int srcId, int dstId, string major, string minor, float delay)
- Parameters
- srcId = Integer ID of the GameObject to specify as the message source.
- dstId = Integer ID of the GameObject to post the message to.
- major = Message major string.
- minor = Message minor string.
- delay = Number of seconds to wait before the message is dispatched, can be 0.0.
- Returned Value
- None
- Syntax
Router.PostMessage(Router,Router.MESSAGE_BROADCAST,"Sinking","StartThePumps",0.0);
- Notes
- Router.PostMessage provides the facility for code which does not belong to a GameObject thread to post a message,
- Since these scripts will not have a GameObject Id an alternative source must be specified.
- Specifying 0 as the source will make the message apper to emanate from the Router itself.
- Specifying MESSAGE_BROADCAST as the destination will send the message to all GameObjects on the map.
Note this function is obsolete, as it requires the use of integer router IDs. To use PostMessage without the Router call GameObject.PostMessage() instead. Only the destination is required, and the source will be the object the function is called on.
For example:
Old - Router.PostMessage(GetId(), myTrain.GetId(), "Animation-Event", "Left-Opening", 0.0); New - PostMessage(myTrain, "Animation-Event", "Left-Opening", 0.0);
Related Methods