How to Use Variables in Sessions (Examples)
From TrainzOnline
(Difference between revisions)
m (→Example 3: Counting Consist Checks) |
m (→Example 2: Event Counter and Message Selection) |
||
Line 228: | Line 228: | ||
<tr valign="top"> | <tr valign="top"> | ||
<td width=10>[[image:DotPoint.JPG|10px|link=]]</td> | <td width=10>[[image:DotPoint.JPG|10px|link=]]</td> | ||
− | <td>A variable, '''SetSPAD''' (value "0" or "1"), is used to indicate whether a SPAD event is to be counted and responded to or not. This is set to "0" or "1" by track triggers</td> | + | <td>A variable, '''SetSPAD''' (value "0" or "1"), is used to indicate whether a SPAD event is to be counted and responded to or not. This is set to "0" or "1" by track triggers. Use the '''[[Session_Rule_List_with_Parameters#Variable_Modify_Rule|Variable Modify Rule]]''' to create and set this variable</td> |
</tr> | </tr> | ||
<tr valign="top"> | <tr valign="top"> | ||
<td>[[image:DotPoint.JPG|10px|link=]]</td> | <td>[[image:DotPoint.JPG|10px|link=]]</td> | ||
− | <td>A variable, '''SPADCounter''', is used to count the SPAD events and is initially set at 0</td> | + | <td>A variable, '''SPADCounter''', is used to count the SPAD events and is initially set at 0. Use the '''[[Session_Rule_List_with_Parameters#Variable_Modify_Rule|Variable Modify Rule]]''' to create and set this variable</td> |
</tr> | </tr> | ||
</table> | </table> | ||
Line 330: | Line 330: | ||
<tr valign="top"> | <tr valign="top"> | ||
<td width=629><span id="stepEx3"></span> | <td width=629><span id="stepEx3"></span> | ||
+ | |||
='''Example 3: Counting Consist Checks'''= | ='''Example 3: Counting Consist Checks'''= | ||
</td> | </td> |
Revision as of 12:08, 3 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.