Class Router

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(PostMessage)
(PostMessage)
 
(2 intermediate revisions by 2 users not shown)
Line 50: Line 50:
 
{{MethodHeader|public obsolete native void PostMessage(int srcId, int dstId, string major, string minor, float delay)}}
 
{{MethodHeader|public obsolete native void PostMessage(int srcId, int dstId, string major, string minor, float delay)}}
 
;Parameters
 
;Parameters
*'''srcId''' = GameObject to specify as the message source.
+
*'''srcId''' = Integer ID  of the GameObject to specify as the message source.
*'''dstId''' = GameObject to specify as the message destination.
+
*'''dstId''' = Integer ID  of the GameObject to post the message to.
 
*'''major''' = Message major string.
 
*'''major''' = Message major string.
 
*'''minor''' = Message minor string.
 
*'''minor''' = Message minor string.
Line 64: Line 64:
 
*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>
 
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);
+
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.
  Now - PostMessage(myTrain, "Animation-Event", "Left-Opening", 0.0);
+
 
 +
For example:
 +
  Old - Router.PostMessage(GetId(), myTrain.GetId(), "Animation-Event", "Left-Opening", 0.0);
 +
  New - PostMessage(myTrain, "Animation-Event", "Left-Opening", 0.0);
 +
 
 +
<br>
  
 
==Related Methods==  
 
==Related Methods==  

Latest revision as of 09:29, 26 February 2024


  • 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

[edit] Constants

public define int MESSAGE_BROADCAST = 0 The message will be sent to all objects in the Router


[edit] 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.


[edit] 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.


[edit] 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);


[edit] Related Methods


[edit] Categories

Personal tools