Class TrainzGameObject

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
m (Change link to library reference, not language reference)
Line 6: Line 6:
  
 
*Base class for a GameObject that is an instance of a Trainz asset.  
 
*Base class for a GameObject that is an instance of a Trainz asset.  
*This class is a parent class for game objects in the Trainz world that are instances of a Trainz asset.
 
  
  
Line 20: Line 19:
 
*Initialisation method which is called by Trainz when the object is first created.  
 
*Initialisation method which is called by Trainz when the object is first created.  
 
*It is up to the script programmer to do any initialization tasks required here.
 
*It is up to the script programmer to do any initialization tasks required here.
*This may include starting a thread if the object is to exist in a persistent state.
+
*This may include starting monitor threads, adding message handlers, and so on.
*Some derived classes have both an Init() and Init(Asset) method. There isn't much difference between them except one gets the Asset as a parameter. It is recommended that you use the Init(Asset) version whenever you can.
+
*Some derived classes have both an Init() and Init(Asset) method. It is recommended that you use the Init(Asset) version whenever you can.
*When overriding this base Init() method, you must call it explicitly by using the inherited keyword in the overridden implementation.
+
*Uses the 'mandatory' keyword, meaning you '''must''' call inherited() when overriding this function.
 
*Since Init() is called from native Trainz code, you cannot use [[Class GameObject#Sleep|Sleep()]] or wait(). However, Init() can start threaded methods that are allowed to sleep and process messages.  
 
*Since Init() is called from native Trainz code, you cannot use [[Class GameObject#Sleep|Sleep()]] or wait(). However, Init() can start threaded methods that are allowed to sleep and process messages.  
 
<br>
 
<br>
Line 31: Line 30:
 
*None
 
*None
 
;Returned Value
 
;Returned Value
*A reference to the current asset
+
*A reference to the owning asset.
 
;Syntax
 
;Syntax
 
  Asset asset = GetAsset();
 
  Asset asset = GetAsset();

Revision as of 11:05, 26 February 2024


  • Base class for a GameObject that is an instance of a Trainz asset.


Init

public void Init(void)
public void Init(Asset asset)
Parameters
  • asset = Reference to the script's associated asset.
Returned Value
  • None
Syntax
  • None, method is automatically called by the game.
Notes
  • Initialisation method which is called by Trainz when the object is first created.
  • It is up to the script programmer to do any initialization tasks required here.
  • This may include starting monitor threads, adding message handlers, and so on.
  • Some derived classes have both an Init() and Init(Asset) method. It is recommended that you use the Init(Asset) version whenever you can.
  • Uses the 'mandatory' keyword, meaning you must call inherited() when overriding this function.
  • Since Init() is called from native Trainz code, you cannot use Sleep() or wait(). However, Init() can start threaded methods that are allowed to sleep and process messages.


GetAsset

public Asset GetAsset(void)
Parameters
  • None
Returned Value
  • A reference to the owning asset.
Syntax
Asset asset = GetAsset();
Notes
  • The returned Asset reference can be used to retrieve the KUID, StringTable or configuration data of the Asset.


Categories

Personal tools