Class TrainzGameObject
From TrainzOnline
(Difference between revisions)
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. | ||
− | |||
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 | + | *This may include starting monitor threads, adding message handlers, and so on. |
− | *Some derived classes have both an Init() and Init(Asset) method | + | *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 [[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 | + | *A reference to the owning asset. |
;Syntax | ;Syntax | ||
Asset asset = GetAsset(); | Asset asset = GetAsset(); |
Revision as of 11:05, 26 February 2024
- API Hierarchy
- GSObject
- GameObject
- Class TrainzGameObject
- GameObject
- GSObject
- Base class for a GameObject that is an instance of a Trainz asset.
Init
public void Init(void)
public void Init(Asset asset)
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.