How to Use Variables in Sessions (Examples)
m |
m |
||
Line 1: | Line 1: | ||
− | The information in this Wiki Page applies to '''TANE''', '''TRS19''' | + | The information in this Wiki Page applies to '''TANE''', '''TRS19''', '''Trainz Plus''' and '''TRS22'''. It gives examples of using variables in Sessions. |
__TOC__ | __TOC__ | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#c1e7e7> |
<tr valign="top"> | <tr valign="top"> | ||
<td colspan=2><span style="font-size: 17px; font-weight: 700;">Main Points:</span></td> | <td colspan=2><span style="font-size: 17px; font-weight: 700;">Main Points:</span></td> | ||
Line 24: | Line 24: | ||
<br> | <br> | ||
The scenarios shown below give examples of how variables can be used to control the operation of a session. | The scenarios shown below give examples of how variables can be used to control the operation of a session. | ||
+ | <br> | ||
<table> <!-- BEGIN Nav Buttons Table --> | <table> <!-- BEGIN Nav Buttons Table --> | ||
<tr valign="top"> | <tr valign="top"> | ||
Line 35: | Line 36: | ||
='''Example 1: Random Passenger Stop'''= | ='''Example 1: Random Passenger Stop'''= | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td>[[file:binoculars.PNG|link=]]</td> | <td>[[file:binoculars.PNG|link=]]</td> | ||
Line 55: | Line 56: | ||
The same logic is repeated for the other two stations with '''stopID''' values of "2" and "3". | The same logic is repeated for the other two stations with '''stopID''' values of "2" and "3". | ||
<br><br> | <br><br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td>[[file:conditions.PNG|link=]]</td> | <td>[[file:conditions.PNG|link=]]</td> | ||
Line 75: | Line 76: | ||
</table> | </table> | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:RulesWiki.PNG|link=]]</td> | <td width="58">[[file:RulesWiki.PNG|link=]]</td> | ||
Line 96: | Line 97: | ||
*'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to open a message window on the screen. | *'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to open a message window on the screen. | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td>[[file:screenshot.PNG|link=]]</td> | <td>[[file:screenshot.PNG|link=]]</td> | ||
Line 109: | Line 110: | ||
</table> | </table> | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td>[[file:explanation.PNG|link=]]</td> | <td>[[file:explanation.PNG|link=]]</td> | ||
Line 122: | Line 123: | ||
**'''Line 5: Variable Check''' The value stored in the variable '''stopID''' is tested "<>1". Line 6 is executed only if '''stopID''' is '''not equal''' to "1". | **'''Line 5: Variable Check''' The value stored in the variable '''stopID''' is tested "<>1". Line 6 is executed only if '''stopID''' is '''not equal''' to "1". | ||
***'''Line 6: Message Popup''' Displays a message window showing that no stop has to be made at Sandplace. | ***'''Line 6: Message Popup''' Displays a message window showing that no stop has to be made at Sandplace. | ||
− | + | <br> | |
<table> <!-- BEGIN Nav Buttons Table --> | <table> <!-- BEGIN Nav Buttons Table --> | ||
<tr valign="top"> | <tr valign="top"> | ||
Line 134: | Line 135: | ||
='''Example 2: Event Counter and Message Selection'''= | ='''Example 2: Event Counter and Message Selection'''= | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:binoculars.PNG|link=]]</td> | <td width="58">[[file:binoculars.PNG|link=]]</td> | ||
Line 143: | Line 144: | ||
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. | 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. | ||
<br><br> | <br><br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:conditions.PNG|link=]]</td> | <td width="58">[[file:conditions.PNG|link=]]</td> | ||
Line 153: | Line 154: | ||
*A variable, '''SPADCounter''', is used to count the SPAD events and is initially set at 0. | *A variable, '''SPADCounter''', is used to count the SPAD events and is initially set at 0. | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:RulesWiki.PNG|link=]]</td> | <td width="58">[[file:RulesWiki.PNG|link=]]</td> | ||
Line 176: | Line 177: | ||
*'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to open a message window on the screen. | *'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to open a message window on the screen. | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:screenshot.PNG|link=]]</td> | <td width="58">[[file:screenshot.PNG|link=]]</td> | ||
Line 189: | Line 190: | ||
</table> | </table> | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:explanation.PNG|link=]]</td> | <td width="58">[[file:explanation.PNG|link=]]</td> | ||
Line 207: | Line 208: | ||
*****'''Line 10: Message Popup''' The second warning message is shown on the screen. | *****'''Line 10: Message Popup''' The second warning message is shown on the screen. | ||
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. | 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. | ||
− | + | <br> | |
<table> <!-- BEGIN Nav Buttons Table --> | <table> <!-- BEGIN Nav Buttons Table --> | ||
<tr valign="top"> | <tr valign="top"> | ||
Line 219: | Line 220: | ||
='''Example 3: Counting Consist Checks'''= | ='''Example 3: Counting Consist Checks'''= | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:binoculars.PNG|link=]]</td> | <td width="58">[[file:binoculars.PNG|link=]]</td> | ||
Line 228: | Line 229: | ||
The '''Consist Check Rule''' cannot be set to trigger only once but sometimes you want it triggered only once on (for example) the 1st, 2nd, 3rd, 4th, etc, 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. | The '''Consist Check Rule''' cannot be set to trigger only once but sometimes you want it triggered only once on (for example) the 1st, 2nd, 3rd, 4th, etc, 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. | ||
<br><br> | <br><br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:conditions.PNG|link=]]</td> | <td width="58">[[file:conditions.PNG|link=]]</td> | ||
Line 237: | Line 238: | ||
*A variable, '''ConsistCount''' is initially set to "0". | *A variable, '''ConsistCount''' is initially set to "0". | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:RulesWiki.PNG|link=]]</td> | <td width="58">[[file:RulesWiki.PNG|link=]]</td> | ||
Line 249: | Line 250: | ||
*'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to place a message on the screen. | *'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to place a message on the screen. | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:screenshot.PNG|link=]]</td> | <td width="58">[[file:screenshot.PNG|link=]]</td> | ||
Line 262: | Line 263: | ||
</table> | </table> | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:explanation.PNG|link=]]</td> | <td width="58">[[file:explanation.PNG|link=]]</td> | ||
Line 273: | Line 274: | ||
**'''Line 3: Variable Check''' Compares the value stored in '''ConsistCounter''' to a set value (in this case 2). If it matches then the next lines are executed. | **'''Line 3: Variable Check''' Compares the value stored in '''ConsistCounter''' to a set value (in this case 2). If it matches then the next lines are executed. | ||
***'''Line 4: Message Popup''' Places a message on the screen. | ***'''Line 4: Message Popup''' Places a message on the screen. | ||
− | + | <br> | |
<table> <!-- BEGIN Nav Buttons Table --> | <table> <!-- BEGIN Nav Buttons Table --> | ||
<tr valign="top"> | <tr valign="top"> | ||
Line 285: | Line 286: | ||
='''Example 4: Train Status'''= | ='''Example 4: Train Status'''= | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:binoculars.PNG|link=]]</td> | <td width="58">[[file:binoculars.PNG|link=]]</td> | ||
Line 294: | Line 295: | ||
Train 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. | Train 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. | ||
<br><br> | <br><br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:conditions.PNG|link=]]</td> | <td width="58">[[file:conditions.PNG|link=]]</td> | ||
Line 303: | Line 304: | ||
*A variable, '''T188Status''' is initially set to "1" signifying that the train is empty. This will be modified to "2" after it has been loaded. | *A variable, '''T188Status''' is initially set to "1" signifying that the train is empty. This will be modified to "2" after it has been loaded. | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:RulesWiki.PNG|link=]]</td> | <td width="58">[[file:RulesWiki.PNG|link=]]</td> | ||
Line 314: | Line 315: | ||
*'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to place a message on the screen. | *'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to place a message on the screen. | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:screenshot.PNG|link=]]</td> | <td width="58">[[file:screenshot.PNG|link=]]</td> | ||
Line 327: | Line 328: | ||
</table> | </table> | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="58">[[file:explanation.PNG|link=]]</td> | <td width="58">[[file:explanation.PNG|link=]]</td> | ||
Line 339: | Line 340: | ||
**'''Line 4: Variable Check''' Compares the value stored in '''T188Status''' to 2, indicating "loaded". If it matches then the next line is executed. | **'''Line 4: Variable Check''' Compares the value stored in '''T188Status''' to 2, indicating "loaded". If it matches then the next line is executed. | ||
***'''Line 5: Message Popup''' Places a message on the screen. | ***'''Line 5: Message Popup''' Places a message on the screen. | ||
− | + | <br> | |
<table> <!-- BEGIN Nav Buttons Table --> | <table> <!-- BEGIN Nav Buttons Table --> | ||
<tr valign="top"> | <tr valign="top"> | ||
Line 351: | Line 352: | ||
='''Variable Rules and Commands'''= | ='''Variable Rules and Commands'''= | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="50">[[file:RulesWiki.PNG|link=]]</td> | <td width="50">[[file:RulesWiki.PNG|link=]]</td> | ||
Line 365: | Line 366: | ||
*'''[[Session_Rule_List_with_Parameters#Variable Show Rule|Variable Show Rule]]''' - adds or removes a specified variable and a descriptive label to the custom HUD. | *'''[[Session_Rule_List_with_Parameters#Variable Show Rule|Variable Show Rule]]''' - adds or removes a specified variable and a descriptive label to the custom HUD. | ||
<br> | <br> | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td width="50">[[file:CommandsWiki.png|link=]]</td> | <td width="50">[[file:CommandsWiki.png|link=]]</td> | ||
Line 375: | Line 376: | ||
*'''[[Driver_Commands_List#Wait Until S-Variable V3|Wait Until S-Variable V3]]''' - AI driver waits for the specified variable condition to occur. | *'''[[Driver_Commands_List#Wait Until S-Variable V3|Wait Until S-Variable V3]]''' - AI driver waits for the specified variable condition to occur. | ||
<table> <!-- BEGIN Nav Buttons Table --> | <table> <!-- BEGIN Nav Buttons Table --> | ||
+ | <br> | ||
<tr valign="top"> | <tr valign="top"> | ||
<td width=729><span id="bottom"></span> </td> | <td width=729><span id="bottom"></span> </td> | ||
Line 386: | Line 388: | ||
---- | ---- | ||
='''Trainz Wiki'''= | ='''Trainz Wiki'''= | ||
− | <table cellpadding= | + | <table cellpadding=4 bgcolor=#ffffff> |
<tr valign="top"> | <tr valign="top"> | ||
<td>[[file:TrainzWiki.png|link=]]</td> | <td>[[file:TrainzWiki.png|link=]]</td> |
Revision as of 08:33, 15 March 2022
The information in this Wiki Page applies to TANE, TRS19, Trainz Plus and TRS22. It gives examples of using variables in Sessions.
Contents |
Main Points: | |
Variables store integer values in Sessions that can be used to:-
|
|
Variables can be used for basic arithmetic by having set values added or subtracted | |
Variables can have random values assigned to them |
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: |
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.
If a stop is required then a predefined Navigation Point is shown to indicate the stopping place.
The same logic is repeated for the other two stations with stopID values of "2" and "3".
Preconditions: |
- The Randomize Rule is used at the start of the session to create a different sequence of random values each time the session is run.
- The Navigation Display Rule is used to create three Navigation Point Sets, one for each stopping place.
- The Navigation Set Hide/Show Rule is used to initially hide all three navigation sets.
- The Variable Random Rule is used to create a variable, stopID, with an integer random value from 1 to 3. Each number representing one of the stops.
Setting the random variable stopID |
Rules Used: |
In addition to those described in the Preconditions above:-
- Trigger Check Rule to trigger the decision and message event.
- Variable Check Rule to check the value held in a session variable.
Checking the variable stopID for the first stopping place |
- Navigation Set Hide/Show Rule to show the navigation set identified by the random variable.
- Message Popup Rule to open a message window on the screen.
Session Editor Screenshot: |
Description: |
- Line 1: Trigger Check The event is triggered when the consist passes over a track trigger.
- Line 2: Variable Check The value stored in the variable stopID is tested "=1". Lines 3 and 4 are executed only if stopID is equal to "1"
- Line 3: Navigation Set Hide/Show Displays a navigation point showing the stopping location.
- Line 4: Message Popup Displays a message window showing that a stop has to be made at Sandplace.
- Line 5: Variable Check The value stored in the variable stopID is tested "<>1". Line 6 is executed only if stopID is not equal to "1".
- Line 6: Message Popup Displays a message window showing that no stop has to be made at Sandplace.
- Line 2: Variable Check The value stored in the variable stopID is tested "=1". Lines 3 and 4 are executed only if stopID is equal to "1"
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: |
- 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.
- A variable, SPADCounter, is used to count the SPAD events and is initially set at 0.
Rules Used: |
- Signal Passed At Danger Check Rule set to trigger on every SPAD event.
- Variable Check Rule to check the value held in a session variable.
- Driver Schedule Rule used to immediately stop the train.
Using the Driver Schedule Rule to halt the train |
- Simultaneous List Rule to force all rules to run simultaneously for speed.
- Variable Modify Rule to alter the value held in a session variable.
- Variable Show Rule adds a session variable to the Heads Up Display.
- Message Popup Rule to open a message window on the screen.
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.
- Line 2: Variable Check The value stored in the variable SetSPAD is tested "=1". If true then the following lines are executed.
- Line 3: Driver Schedule: The current schedule (if any) for the user controlled driver is replaced with a Halt Train command to bring the train to an immediate stop.
- Line 4: Variable Modify The value stored in the variable SPADCounter is increased by 1.
- Line 5: Simultaneous List This forces all the Variable Check Rules to be run simultaneously. This is not strictly necessary but without it all the Variable Check Rules will be tested, one after the other, when only one (or none) of them will be executed. This will (marginally) speed up the processing.
- Line 6: Variable Check The value stored in the variable SPADCounter is tested "=1". If true then the first SPAD event has occurred and the following lines are executed.
- Line 7: Variable Show The value stored in the variable SPADCounter is added to the Custom HUD. Each time the value changes it will be updated in the HUD.
- Line 8: Message Popup The first warning message is shown on the screen.
- Line 9: Variable Check The value stored in the variable SPADCounter is tested "=2". If true then the second SPAD event has occurred and the following line is executed.
- Line 10: Message Popup The second warning message is shown on the screen.
- Line 6: Variable Check The value stored in the variable SPADCounter is tested "=1". If true then the first SPAD event has occurred and the following lines are executed.
- Line 2: Variable Check The value stored in the variable SetSPAD is tested "=1". If true then the following lines are executed.
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 1st, 2nd, 3rd, 4th, etc, 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: |
- A variable, ConsistCount is initially set to "0".
Rules Used: |
- Consist Check Rule set to trigger when a specific consist has been formed.
- Variable Modify Rule to set and increase the value held in a session variable.
- Variable Check Rule to check the value held in a session variable.
- Message Popup Rule to place a message on the screen.
Session Editor Screenshot: |
Description: |
- Line 1: Consist Check Rule Triggered when the specified consist has been found.
- Line 2: Variable Modify Rule Adds 1 to the variable ConsistCounter.
- Line 3: Variable Check Compares the value stored in ConsistCounter to a set value (in this case 2). If it matches then the next lines are executed.
- Line 4: Message Popup Places a message on the screen.
Example 4: Train Status
The Scenario: |
Train 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: |
- A variable, T188Status is initially set to "1" signifying that the train is empty. This will be modified to "2" after it has been loaded.
Rules Used: |
- Trigger Check Rule to trigger the event when the consist reaches the trigger
- Variable Check Rule to check the value held in a session variable.
- Message Popup Rule to place a message on the screen.
Session Editor Screenshot: |
Description: |
- Line 1: Trigger Check Rule Triggered by the train. This is NOT set to trigger once only.
- Line 2: Variable Check Compares the value stored in T188Status to 1, indicating "empty". If it matches then the next line is executed.
- Line 3: Message Popup Places a message on the screen.
- Line 4: Variable Check Compares the value stored in T188Status to 2, indicating "loaded". If it matches then the next line is executed.
- Line 5: Message Popup Places a message on the screen.
- Line 2: Variable Check Compares the value stored in T188Status to 1, indicating "empty". If it matches then the next line is executed.
Variable Rules and Commands
These are the Session Rules that can access, create and/or modify Session variables |
- Randomize Rule - creates a different set of random numbers every time a session is run.
- Variable Check Rule - executes child rules according to the value of a specified variable.
- Variable Modify Rule - changes the value of a specified variable and creates new variables by setting their initial values.
- Variable Modify Continuous Rule - continuously changes the value of a specified variable.
- Variable Random Rule - assigns a random value to a variable.
- Variable Show Rule - adds or removes a specified variable and a descriptive label to the custom HUD.
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. |
- Skip if Session Variable - conditionally jumps to the named command label in the Driver Command Bar if a selected session variable meets a set condition.
- Wait Until S-Variable V3 - AI driver waits for the specified variable condition to occur.
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.