How to Use Variables in Sessions (Examples)
From TrainzOnline
(Difference between revisions)
m (→Example 4: Train Status) |
m |
||
Line 133: | Line 133: | ||
<table> | <table> | ||
<tr valign="top"> | <tr valign="top"> | ||
− | <td | + | <td width=10>[[image:DotPoint.JPG|10px|link=]]</td> |
+ | <td>'''[[Session_Rule_List_with_Parameters#Navigation_Display_Rule|Navigation Display Rule]]''' to create three Navigation Point Sets (in '''Preconditions''' above)</td> | ||
</tr> | </tr> | ||
<tr valign="top"> | <tr valign="top"> | ||
− | <td | + | <td>[[image:DotPoint.JPG|10px|link=]]</td> |
+ | <td>'''[[Session_Rule_List_with_Parameters#Navigation_Set_Hide/Show_Rule|Navigation Set Hide/Show Rule]]''' to hide all three navigation sets (in '''Preconditions''' above) and to reveal one set identified by the random variable</td> | ||
+ | </tr> | ||
+ | <tr valign="top"> | ||
+ | <td>[[image:DotPoint.JPG|10px|link=]]</td> | ||
+ | <td>'''[[Session_Rule_List_with_Parameters#Variable_Random_Rule|Variable Random Rule]]''' to create the variable '''stopID''' (in '''Preconditions''' above)</td> | ||
+ | </tr> | ||
+ | <tr valign="top"> | ||
+ | <td>[[image:DotPoint.JPG|10px|link=]]</td> | ||
<td>'''[[Session_Rule_List_with_Parameters#Trigger_Check_Rule|Trigger Check Rule]]''' to trigger the decision and message event</td> | <td>'''[[Session_Rule_List_with_Parameters#Trigger_Check_Rule|Trigger Check Rule]]''' to trigger the decision and message event</td> | ||
</tr> | </tr> | ||
Line 151: | Line 160: | ||
</table> | </table> | ||
</td> | </td> | ||
− | |||
− | |||
− | |||
− | |||
</tr> | </tr> | ||
<tr valign="top"> | <tr valign="top"> | ||
Line 322: | Line 327: | ||
<tr valign="top"> | <tr valign="top"> | ||
<!-- <td> </td> --> | <!-- <td> </td> --> | ||
− | <td>Lines 9 and 10 are then repeated with variations as shown. If more than 5 SPADs occur, then no new messages will be shown (the driver is clearly taking no notice so what is the point?) but the '''SPADCounter''' will continue to be updated. | + | <td>Lines <span style="font-weight: 700; font-size: 15px; color: white; background-color: black;"> 9 </span> and <span style="font-weight: 700; font-size: 15px; color: white; background-color: black;"> 10 </span> are then repeated with variations as shown. If more than 5 SPADs occur, then no new messages will be shown (the driver is clearly taking no notice so what is the point?) but the '''SPADCounter''' will continue to be updated. |
</td> | </td> | ||
</tr> | </tr> |
Revision as of 19:35, 4 October 2023
The information in this Wiki Page applies to TANE, TRS19, Trainz Plus and TRS22. It gives examples of using variables in Sessions.
|
|
The scenarios shown below give examples of how variables can be used to control the operation of a session.
Example 1: Random Passenger Stop |
The Scenario: | ||||
In the example shown below a random variable is to be used to decide which one of 3 stations a user controlled train will be required to stop at. The user will be informed of the decision, to stop or not, by a message placed on the screen before they reach each station. When the train approaches the first possible stopping place, Sandplace, the session checks the value stored in "stopID" and if it is "1" then a stop will be requested. | ||||
|
Preconditions: | ||||||||||||
|
Rules Used: | ||||||||||||||
|
Session Editor Screenshot: | |
Description: | |
Line 1 : Trigger Check The event is triggered when the consist passes over a track trigger. This executes the following rules:-
|
Example 2: Event Counter and Message Selection |
The Scenario: | |
Each time a user causes a SPAD (Signal Passed At Danger) at specific locations, the event is counted and an appropriate message is displayed on the screen. The tone of the messages becomes more severe with each occurance. |
Preconditions: | ||||
|
Rules Used: | ||||||||||||||||
|
Session Editor Screenshot: | |
Description: | |
Line 1 : Signal Passed At Danger The event is triggered every time a consist passes a signal (or stop sign) set at STOP. This executes the following lines:-
|
|
Lines 9 and 10 are then repeated with variations as shown. If more than 5 SPADs occur, then no new messages will be shown (the driver is clearly taking no notice so what is the point?) but the SPADCounter will continue to be updated. |
Example 3: Counting Consist Checks |
The Scenario: | |
The Consist Check Rule cannot be set to trigger only once but sometimes you want it triggered only once on (for example) the 2nd time that a particular consist is formed. This example uses a variable to count the number of times the rule has been triggered and acts only when a set count has been reached. It could easily be modified to trigger a set number of times. |
Preconditions: | ||
|
Rules Used: | ||||||||
|
Session Editor Screenshot: | |
Description: | |
Line 1 : Consist Check Rule Triggered when the specified consist has been found. This executes the following lines:-
|
Example 4: Train Status |
The Scenario: | |
A consist identified by number 188 passes over the same trigger twice, once when empty and once when loaded. Each time the user needs to be given a different set of instructions |
Preconditions: | ||
|
Rules Used: | ||||||
|
Session Editor Screenshot: | |
Description: | |
Line 1 : Trigger Check Rule Triggered by the train. This is NOT set to trigger once only. When triggered it will execute the following lines:-
|
Variable Rules and Commands |
These are the Session Rules that can access, create and/or modify Session variables
|
These are the Driver Commands that can access Session variables. The InputTable Rule must be added to the Session and configured with the names of the variables before these Driver Commands can be used.
|
Trainz Wiki
More Tutorials and Guides to Using Trainz |
This page was created by Trainz user pware in April 2018 and was last updated as shown below.