Class Router

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(PostMessage)
m (PostMessage)
Line 60: Line 60:
 
  Router.PostMessage(Router,Router.MESSAGE_BROADCAST,"Sinking","StartThePumps",0.0);
 
  Router.PostMessage(Router,Router.MESSAGE_BROADCAST,"Sinking","StartThePumps",0.0);
 
;Notes
 
;Notes
*Router.PostMessage provides the facility for code which does not belong to a GameObjject thread to post a message,
+
*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.
 
*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 ''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.
 
*Specifying MESSAGE_BROADCAST as the destination will send the message to all GameObjects on the map.
 
<br><br>
 
<br><br>
This Method is obsolete, it uses an integer lookup with the Router, which now needs to be an object lookup
+
This Method is obsolete, it uses an integer lookup with the Router, which now needs to be an object lookup. To use PostMessage without the Router, use a GameObject PostMessage instead. Only the destination is required.
To use PostMessage without the Router, use a GameObject PostMessage instead.
+
  
 
  Was - Router.PostMessage (me.GetId(), me.GetId(), "Timer-Event", "", 2.0);
 
  Was - Router.PostMessage (me.GetId(), me.GetId(), "Timer-Event", "", 2.0);

Revision as of 03:09, 13 October 2022


  • 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)
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 = 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 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.



This Method is obsolete, it uses an integer lookup with the Router, which now needs to be an object lookup. To use PostMessage without the Router, use a GameObject PostMessage instead. Only the destination is required.

Was - Router.PostMessage (me.GetId(), me.GetId(), "Timer-Event", "", 2.0);
Now - PostMessage(me, "Timer-Event", "", 2.0);
Was - Router.PostMessage (me.GetId(), nMyTrainID, "Animation-Event", "Left-Opening", 0.0);
Now - PostMessage(myTrain, "Timer-Event", "", 2.0);

Related Methods


Categories

Personal tools