Class Crossing
From TrainzOnline
(Difference between revisions)
(→SetCrossingAutomatic) |
(→SetCrossingState) |
||
(8 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
*[[TrainzScript Library Reference|API Hierarchy]] | *[[TrainzScript Library Reference|API Hierarchy]] | ||
− | **[[Class GSObject|GSObject]] | + | **[[Class GSObject|GSObject]] |
***[[Class GameObject|GameObject]] | ***[[Class GameObject|GameObject]] | ||
****[[Class TrainzGameObject|TrainzGameObject]] | ****[[Class TrainzGameObject|TrainzGameObject]] | ||
− | ****[[Class PropertyObject|PropertyObject]] | + | ****[[Class PropertyObject|PropertyObject]] |
*****[[Class MeshObject|MeshObject]] | *****[[Class MeshObject|MeshObject]] | ||
******[[Class MapObject|MapObject]] | ******[[Class MapObject|MapObject]] | ||
*******[[Class SceneryWithTrack|SceneryWithTrack]] | *******[[Class SceneryWithTrack|SceneryWithTrack]] | ||
− | ********Crossing | + | ********[[Class Crossing|Crossing]] |
<br> | <br> | ||
− | * | + | *A script class to represent a level crossing or similar object. |
− | *By default a crossing is automatically controlled by | + | *By default a crossing is automatically controlled by Trainz native code. |
− | * | + | *The crossing will close when a train is within the trigger distance of the crossing (as specified by the asset). |
− | *The crossing will reopen | + | *The crossing will reopen to road traffic when there are no trains within the trigger disance. |
− | + | ||
<br> | <br> | ||
Line 21: | Line 20: | ||
===Crossing States=== | ===Crossing States=== | ||
---- | ---- | ||
− | *These values define the | + | *These values define the possible state of a crossing. |
− | + | ||
{{TableHeader|width=95%|margin=15px}} | {{TableHeader|width=95%|margin=15px}} | ||
|width=375|public define int CROSSING_STATE_OPEN = 0||Crossing is open to road traffic. | |width=375|public define int CROSSING_STATE_OPEN = 0||Crossing is open to road traffic. | ||
Line 37: | Line 35: | ||
---- | ---- | ||
*Messages sent to and from Crossings objects are listed below: | *Messages sent to and from Crossings objects are listed below: | ||
− | *Note that | + | *Note that more messages are also posted by the parent [[Class SceneryWithTrack|SceneryWithTrack]] class. |
<br> | <br> | ||
{{TableHeader|width=50%|margin=15px}} | {{TableHeader|width=50%|margin=15px}} | ||
Line 46: | Line 44: | ||
|- | |- | ||
|[[Object Messages|Object]]||Leave||Crossing||Crossing | |[[Object Messages|Object]]||Leave||Crossing||Crossing | ||
+ | |- | ||
+ | |Crossing||StateChanged||Crossing||Crossing | ||
|} | |} | ||
<br> | <br> | ||
Line 56: | Line 56: | ||
*None | *None | ||
;Returned Value | ;Returned Value | ||
− | * | + | *Whether the crossing operating in automatic mode. |
;Syntax | ;Syntax | ||
− | bool | + | bool bIsAutomaticMode = crossing.GetCrossingAutomatic(); |
;Notes | ;Notes | ||
<br> | <br> | ||
Line 67: | Line 67: | ||
*None | *None | ||
;Returned Value | ;Returned Value | ||
− | * | + | *Whether any trains are within the trigger radius (default 200m, overridable by the asset). |
;Syntax | ;Syntax | ||
− | bool | + | bool bHasNearbyTrain = crossing.GetCrossingHasNearbyTrain(); |
;Notes | ;Notes | ||
+ | *This function will continue to operate when the crossing is in manual script mode. | ||
+ | *The default crossing trigger distance is 200 metres, but this can be overridden by the asset config. | ||
+ | *The crossing trigger distance cannot be overridden by script. | ||
+ | <br> | ||
+ | |||
+ | ===GetCrossingOwner=== | ||
+ | {{MethodHeader|public native TrainzGameObject GetCrossingOwner(void)}} | ||
+ | ;Parameters | ||
+ | *None | ||
+ | ;Returned Value | ||
+ | *The crossing owner, or null. | ||
+ | ;Syntax; | ||
+ | if (crossing.GetCrossingOwner()) | ||
+ | return; // The crossing is owned, so we cannot alter state. | ||
+ | ;Notes | ||
+ | *Returns the crossing owner, if any. | ||
+ | *Owned crossings cannot have their state altered by any script except the owner, including the crossing itself. | ||
+ | *Introduced for [[Class InterlockingTower|Interlocking Towers]]. | ||
<br> | <br> | ||
Line 80: | Line 98: | ||
*One of the crossing state constants indicating the current condition of the crossing. | *One of the crossing state constants indicating the current condition of the crossing. | ||
;Syntax | ;Syntax | ||
− | + | switch(GetCrossingState()) | |
+ | { | ||
+ | case CROSSING_STATE_OPEN: | ||
+ | // Crossing is open to road traffic. | ||
+ | break; | ||
+ | |||
+ | case CROSSING_STATE_CLOSING: | ||
+ | case CROSSING_STATE_CLOSED: | ||
+ | case CROSSING_STATE_OPENING: | ||
+ | // Crossing is NOT open to road traffic. | ||
+ | break; | ||
+ | } | ||
;Notes | ;Notes | ||
− | * | + | *A "Crossing","StateChanged" message will be posted to the crossing whenever this value changes. |
<br> | <br> | ||
===SetCrossingAutomatic=== | ===SetCrossingAutomatic=== | ||
− | {{MethodHeader|public native void SetCrossingAutomatic(SecurityToken, bool auto)}} | + | {{MethodHeader|public native void SetCrossingAutomatic(SecurityToken token, bool auto)}} |
;Parameters | ;Parameters | ||
− | *'''auto''' = True to select automatic mode, false to | + | *'''token''' = A token for the crossing owner with rights "crossing-state", or null. |
+ | *'''auto''' = True to select automatic mode, false to disable automatic control. | ||
;Returned Value | ;Returned Value | ||
*None | *None | ||
;Syntax | ;Syntax | ||
− | + | SetCrossingAutomatic(null, false); | |
+ | ;Notes | ||
+ | *The token is unused if the crossing is unowned, and can be passed as null. | ||
+ | <br> | ||
+ | |||
+ | ===SetCrossingOwner=== | ||
+ | {{MethodHeader|public native void SetCrossingOwner(SecurityToken token, TrainzGameObject owner)}} | ||
+ | ;Parameters | ||
+ | *'''token''' - A token for the crossing owner (new and current, if applicable) with rights "crossing-owner". | ||
+ | *'''owner''' - New owner to set, may be null. | ||
+ | ;Returned Value | ||
+ | *Whether the call succeeded, and the crossing owner was changed. | ||
+ | ;Syntax; | ||
+ | string[] rights = new string[1]; | ||
+ | rights[0] = "crossing-owner"; | ||
+ | SecurityToken token = IssueSecurityToken(GetAsset().GetKUID(), rights); | ||
+ | |||
+ | crossing.SetCrossingOwner(token, me); | ||
;Notes | ;Notes | ||
− | + | *Updates the crossing 'owner', which is used to lock access to various functions. | |
+ | *Owned crossings cannot have their state altered by any script except the owner, including the crossing itself. | ||
+ | *Introduced for [[Class InterlockingTower|Interlocking Towers]]. | ||
<br> | <br> | ||
===SetCrossingState=== | ===SetCrossingState=== | ||
− | {{MethodHeader|public native void SetCrossingState(int state)}} | + | {{MethodHeader|public native void SetCrossingState(SecurityToken token, int state)}} |
;Parameters | ;Parameters | ||
+ | *'''token''' = A token for the crossing owner with rights "crossing-state", or null. | ||
*'''state''' = One of the crossing state constants indicating which state to set. | *'''state''' = One of the crossing state constants indicating which state to set. | ||
;Returned Value | ;Returned Value | ||
*None | *None | ||
;Syntax | ;Syntax | ||
− | + | SetCrossingState(null, Crossing.CROSSING_STATE_CLOSED); | |
;Notes | ;Notes | ||
− | * | + | *If you intend to alter the crossing state you should first disable automatic control (See SetCrossingAutomatic) |
− | + | *The crossing state will be altered as requested even if the crossing is under automatic control, but native code may quickly change it back. | |
+ | *The token is unused if the crossing is unowned, and can be passed as null. | ||
<br> | <br> | ||
==Categories== | ==Categories== | ||
[[Category:Script Class]] | [[Category:Script Class]] |
Latest revision as of 15:02, 26 February 2024
- A script class to represent a level crossing or similar object.
- By default a crossing is automatically controlled by Trainz native code.
- The crossing will close when a train is within the trigger distance of the crossing (as specified by the asset).
- The crossing will reopen to road traffic when there are no trains within the trigger disance.
Contents |
[edit] Constants & Messages
[edit] Crossing States
- These values define the possible state of a crossing.
public define int CROSSING_STATE_OPEN = 0 | Crossing is open to road traffic. |
public define int CROSSING_STATE_CLOSING = 1 | Crossing is in the act of closing. |
public define int CROSSING_STATE_CLOSED = 2 | Crossing is closed to road traffic. |
public define int CROSSING_STATE_OPENING = 3 | Crossing is in the act of opening. |
[edit] Related Messages
- Messages sent to and from Crossings objects are listed below:
- Note that more messages are also posted by the parent SceneryWithTrack class.
Major | Minor | Source | Destination |
Object | Enter | Crossing | Crossing |
Object | Leave | Crossing | Crossing |
Crossing | StateChanged | Crossing | Crossing |
[edit] Methods
[edit] GetCrossingAutomatic
public native bool GetCrossingAutomatic(void)
- Parameters
- None
- Returned Value
- Whether the crossing operating in automatic mode.
- Syntax
bool bIsAutomaticMode = crossing.GetCrossingAutomatic();
- Notes
[edit] GetCrossingHasNearbyTrain
public native bool GetCrossingHasNearbyTrain(void)
- Parameters
- None
- Returned Value
- Whether any trains are within the trigger radius (default 200m, overridable by the asset).
- Syntax
bool bHasNearbyTrain = crossing.GetCrossingHasNearbyTrain();
- Notes
- This function will continue to operate when the crossing is in manual script mode.
- The default crossing trigger distance is 200 metres, but this can be overridden by the asset config.
- The crossing trigger distance cannot be overridden by script.
[edit] GetCrossingOwner
public native TrainzGameObject GetCrossingOwner(void)
- Parameters
- None
- Returned Value
- The crossing owner, or null.
- Syntax;
if (crossing.GetCrossingOwner()) return; // The crossing is owned, so we cannot alter state.
- Notes
- Returns the crossing owner, if any.
- Owned crossings cannot have their state altered by any script except the owner, including the crossing itself.
- Introduced for Interlocking Towers.
[edit] GetCrossingState
public native int GetCrossingState(void)
- Parameters
- None
- Returned Value
- One of the crossing state constants indicating the current condition of the crossing.
- Syntax
switch(GetCrossingState()) { case CROSSING_STATE_OPEN: // Crossing is open to road traffic. break; case CROSSING_STATE_CLOSING: case CROSSING_STATE_CLOSED: case CROSSING_STATE_OPENING: // Crossing is NOT open to road traffic. break; }
- Notes
- A "Crossing","StateChanged" message will be posted to the crossing whenever this value changes.
[edit] SetCrossingAutomatic
public native void SetCrossingAutomatic(SecurityToken token, bool auto)
- Parameters
- token = A token for the crossing owner with rights "crossing-state", or null.
- auto = True to select automatic mode, false to disable automatic control.
- Returned Value
- None
- Syntax
SetCrossingAutomatic(null, false);
- Notes
- The token is unused if the crossing is unowned, and can be passed as null.
[edit] SetCrossingOwner
public native void SetCrossingOwner(SecurityToken token, TrainzGameObject owner)
- Parameters
- token - A token for the crossing owner (new and current, if applicable) with rights "crossing-owner".
- owner - New owner to set, may be null.
- Returned Value
- Whether the call succeeded, and the crossing owner was changed.
- Syntax;
string[] rights = new string[1]; rights[0] = "crossing-owner"; SecurityToken token = IssueSecurityToken(GetAsset().GetKUID(), rights);
crossing.SetCrossingOwner(token, me);
- Notes
- Updates the crossing 'owner', which is used to lock access to various functions.
- Owned crossings cannot have their state altered by any script except the owner, including the crossing itself.
- Introduced for Interlocking Towers.
[edit] SetCrossingState
public native void SetCrossingState(SecurityToken token, int state)
- Parameters
- token = A token for the crossing owner with rights "crossing-state", or null.
- state = One of the crossing state constants indicating which state to set.
- Returned Value
- None
- Syntax
SetCrossingState(null, Crossing.CROSSING_STATE_CLOSED);
- Notes
- If you intend to alter the crossing state you should first disable automatic control (See SetCrossingAutomatic)
- The crossing state will be altered as requested even if the crossing is under automatic control, but native code may quickly change it back.
- The token is unused if the crossing is unowned, and can be passed as null.