Class Router
From TrainzOnline
(Difference between revisions)
(→Categories) |
m (1 revision) |
Revision as of 23:58, 3 February 2010
- 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 native void PostMessage(int srcId, int dstId, string major, string minor, float delay)
- Parameters
- srcId = GameObject to specify as the message source.
- dstId = GameObject to specify as the message destination.
- 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 GameObjject 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.
Related Methods