How to Use Variables in Sessions (Examples)

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
m (Trainz Wiki)
(Example 1: Random Passenger Stop)
(21 intermediate revisions by one user not shown)
Line 1: Line 1:
The screenshots shown below give examples of how variables can be used to control the operation of a session.
+
The information in this Wiki Page applies to both '''TANE''' and '''TRS19'''.
  
 +
__TOC__
 +
<br>
 +
The screenshots shown below give examples of how variables can be used to control the operation of a session.
 +
<br>
 
='''Example 1: Random Passenger Stop'''=
 
='''Example 1: Random Passenger Stop'''=
  
==The Scenario==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td>[[file:binoculars.PNG]]</td>
 +
<td width="640"><font size="3">'''The Scenario:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
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.
 
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.
  
==Preconditions==
+
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.
 +
<table>
 +
<tr>
 +
<td>[[file:RandomLogic.jpg]]</td>
 +
</tr>
 +
</table>
  
 +
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".
 +
<br><br>
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td>[[file:conditions.PNG]]</td>
 +
<td width="640"><font size="3">'''Preconditions:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
*The '''[[Session_Rule_List_with_Parameters#Randomize_Rule|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 '''[[Session_Rule_List_with_Parameters#Randomize_Rule|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 '''[[Session_Rule_List_with_Parameters#Navigation_Display_Rule|Navigation Display Rule]]''' is used to create a Navigation Point Set.
+
*The '''[[Session_Rule_List_with_Parameters#Navigation_Display_Rule|Navigation Display Rule]]''' is used to create three Navigation Point Sets, one for each stopping place.
 +
*The '''[[Session_Rule_List_with_Parameters#Navigation_Set_Hide/Show_Rule|Navigation Set Hide/Show Rule]]''' is used to initially hide all three navigation sets.
 
*The '''[[Session_Rule_List_with_Parameters#Variable_Random_Rule|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.
 
*The '''[[Session_Rule_List_with_Parameters#Variable_Random_Rule|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.
 
<table>
 
<table>
Line 20: Line 46:
 
</tr>
 
</tr>
 
</table>
 
</table>
 
+
<br>
==Program Logic==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
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.
+
<td width="58">[[file:RulesWiki.PNG]]</td>
<table>
+
<td width="640"><font size="3">'''Rules Used:'''</font><br>
<tr>
+
----</td>
<td>[[file:RandomLogic.jpg]]</td>
+
 
</tr>
 
</tr>
 
</table>
 
</table>
 
+
In addition to those described in the '''Preconditions''' above:-
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".
+
 
+
==Rules Used==
+
 
+
 
*'''[[Session_Rule_List_with_Parameters#Trigger_Check_Rule|Trigger Check Rule]]''' to trigger the decision and message event.
 
*'''[[Session_Rule_List_with_Parameters#Trigger_Check_Rule|Trigger Check Rule]]''' to trigger the decision and message event.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Check_Rule|Variable Check Rule]]''' to check the value held in a session variable.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Check_Rule|Variable Check Rule]]''' to check the value held in a session variable.
Line 43: Line 62:
 
</tr>
 
</tr>
 
<tr>
 
<tr>
<td>Checking the variable '''stopID'''</td>
+
<td>Checking the variable '''stopID''' for the first stopping place</td>
 
</tr>
 
</tr>
 
</table>
 
</table>
*'''[[Session_Rule_List_with_Parameters#Navigation_Set_Hide/Show_Rule|Navigation Set Hide/Show Rule]]''' to display a predefined navigation point.
+
*'''[[Session_Rule_List_with_Parameters#Navigation_Set_Hide/Show_Rule|Navigation Set Hide/Show Rule]]''' to show the navigation set identified by the random variable.
 
*'''[[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>
==Session Rules Screenshot==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td>[[file:screenshot.PNG]]</td>
 +
<td width="640"><font size="3">'''Session Editor Screenshot:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
<table>
 
<table>
 
<tr>
 
<tr>
Line 56: Line 80:
 
</tr>
 
</tr>
 
</table>
 
</table>
 
+
<br>
==Explanation==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td>[[file:explanation.PNG]]</td>
 +
<td width="640"><font size="3">'''Description:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
*'''Line 1: Trigger Check''' The event is triggered when the consist passes over a track trigger.
 
*'''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 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 66: Line 95:
 
***'''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>
 
<br>
 +
 
='''Example 2: Event Counter and Message Selection'''=
 
='''Example 2: Event Counter and Message Selection'''=
  
==The Scenario==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:binoculars.PNG]]</td>
 +
<td width="640"><font size="3">'''The Scenario:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
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>
==Preconditions==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:conditions.PNG]]</td>
 +
<td width="640"><font size="3">'''Preconditions:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
*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, '''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.
 
*A variable, '''SPADCounter''', is used to count the SPAD events and is initially set at 0.
 
+
<br>
==Rules Used==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:RulesWiki.PNG]]</td>
 +
<td width="640"><font size="3">'''Rules Used:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
*'''[[Session_Rule_List_with_Parameters#Signal_Passed_At_Danger_Check_Rule|Signal Passed At Danger Check Rule]]''' set to trigger on every SPAD event.
 
*'''[[Session_Rule_List_with_Parameters#Signal_Passed_At_Danger_Check_Rule|Signal Passed At Danger Check Rule]]''' set to trigger on every SPAD event.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Check_Rule|Variable Check Rule]]''' to check the value held in a session variable.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Check_Rule|Variable Check Rule]]''' to check the value held in a session variable.
Line 94: Line 139:
 
*'''[[Session_Rule_List_with_Parameters#Variable_Show_Rule|Variable Show Rule]]''' adds a session variable to the Heads Up Display.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Show_Rule|Variable Show Rule]]''' adds a session variable to the Heads Up Display.
 
*'''[[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>
==Session Rules Screenshot==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:screenshot.PNG]]</td>
 +
<td width="640"><font size="3">'''Session Editor Screenshot:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
<table>
 
<table>
 
<tr>
 
<tr>
Line 102: Line 152:
 
</tr>
 
</tr>
 
</table>
 
</table>
 
+
<br>
==Explanation==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:explanation.PNG]]</td>
 +
<td width="640"><font size="3">'''Description:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
*'''Line 1: Signal Passed At Danger''' The event is triggered every time a consist passes a signal (or stop sign) set at STOP.
 
*'''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 2: Variable Check''' The value stored in the variable '''SetSPAD''' is tested "=1". If true then the following lines are executed.
Line 117: Line 172:
 
Lines 9 and 10 are then repeated with variations as shown. If more than 5 SPADs occur, then no further 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 further 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>
 
<br>
 +
 
='''Example 3: Counting Consist Checks'''=
 
='''Example 3: Counting Consist Checks'''=
  
==The Scenario==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:binoculars.PNG]]</td>
 +
<td width="640"><font size="3">'''The Scenario:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
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>
==Preconditions==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
*A variable, '''ConsistCounter''' is initially set to "0".
+
<td width="58">[[file:conditions.PNG]]</td>
 
+
<td width="640"><font size="3">'''Preconditions:'''</font><br>
==Rules Used==
+
----</td>
 
+
</tr>
 +
</table>
 +
*A variable, '''ConsistCount''' is initially set to "0".
 +
<br>
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td width="58">[[file:RulesWiki.PNG]]</td>
 +
<td width="640"><font size="3">'''Rules Used:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
*'''[[Session_Rule_List_with_Parameters#Consist_Check_Rule|Consist Check Rule]]''' set to trigger when a specific consist has been formed.
 
*'''[[Session_Rule_List_with_Parameters#Consist_Check_Rule|Consist Check Rule]]''' set to trigger when a specific consist has been formed.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Modify_Rule|Variable Modify Rule]]''' to set and increase the value held in a session variable.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Modify_Rule|Variable Modify Rule]]''' to set and increase the value held in a session variable.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Check_Rule|Variable Check Rule]]''' to check the value held in a session variable.
 
*'''[[Session_Rule_List_with_Parameters#Variable_Check_Rule|Variable Check Rule]]''' to check the value held in a session variable.
 
*'''[[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>
==Session Rules Screenshot==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:screenshot.PNG]]</td>
 +
<td width="640"><font size="3">'''Session Editor Screenshot:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
<table>
 
<table>
 
<tr>
 
<tr>
Line 141: Line 217:
 
</tr>
 
</tr>
 
</table>
 
</table>
 
+
<br>
==Explanation==
+
<table cellpadding="4" bgcolor=#ffffff>
 
+
<tr valign="top">
 +
<td width="58">[[file:explanation.PNG]]</td>
 +
<td width="640"><font size="3">'''Description:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 
*'''Line 1: Consist Check Rule''' Triggered when the specified consist has been found.
 
*'''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 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 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>
  
 +
='''Example 4: Train Status'''=
 +
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td width="58">[[file:binoculars.PNG]]</td>
 +
<td width="640"><font size="3">'''The Scenario:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 +
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>
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td width="58">[[file:conditions.PNG]]</td>
 +
<td width="640"><font size="3">'''Preconditions:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 +
*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>
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td width="58">[[file:RulesWiki.PNG]]</td>
 +
<td width="640"><font size="3">'''Rules Used:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 +
*'''[[Session_Rule_List_with_Parameters#Trigger_Check_Rule|Trigger Check Rule]]''' to trigger the event when the consist reaches the trigger
 +
*'''[[Session_Rule_List_with_Parameters#Variable_Check_Rule|Variable Check Rule]]''' to check the value held in a session variable.
 +
*'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to place a message on the screen.
 +
<br>
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td width="58">[[file:screenshot.PNG]]</td>
 +
<td width="640"><font size="3">'''Session Editor Screenshot:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 +
<table>
 +
<tr>
 +
<td>[[file:VariableTrainTrigger.JPG]]</td>
 +
</tr>
 +
</table>
 +
<br>
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td width="58">[[file:explanation.PNG]]</td>
 +
<td width="640"><font size="3">'''Description:'''</font><br>
 +
----</td>
 +
</tr>
 +
</table>
 +
*'''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.
 
----
 
----
 
----
 
----
 
<br>
 
<br>
 +
 
='''Trainz Wiki'''=
 
='''Trainz Wiki'''=
 +
<table cellpadding="4" bgcolor=#ffffff>
 +
<tr valign="top">
 +
<td>[[file:TrainzWiki.png]]</td>
 +
<td>
 +
<font size="3">'''More Tutorials and Guides to Using Trainz'''</font><br>
 
*'''<span class="plainlinks">[http://online.ts2009.com/mediaWiki/index.php/HowTo How to Guides]</span>'''
 
*'''<span class="plainlinks">[http://online.ts2009.com/mediaWiki/index.php/HowTo How to Guides]</span>'''
 +
*'''[[Driver Commands List]]'''
 
*'''[[Session Rule List with Parameters|Session Rules List (Alphabetical) with Parameters]]'''
 
*'''[[Session Rule List with Parameters|Session Rules List (Alphabetical) with Parameters]]'''
 
*'''[[Session Rules By Categories With Properties|Session Rules List (Categories) With Parameters]]'''
 
*'''[[Session Rules By Categories With Properties|Session Rules List (Categories) With Parameters]]'''
<br>
+
</td>
<font size="3">'''Route Creation Tutorials:'''</font>
+
</tr>
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
+
</table>
*'''[[How to Use Bulk Asset Update/Replace Tool]]'''
+
*'''[[How to Use Layers]]'''
+
</div>
+
<br>
+
<font size="3">'''Session Creation Tutorials:'''</font>
+
<div style="column-count:2;-moz-column-count:2;-webkit-column-count:2">
+
*'''[[How to Create a HTML Asset|How to Create a HTML Asset (Session Introduction Page and In Game Messages)]]'''
+
*'''[[How to Control Junctions in Sessions]]'''
+
*'''[[How to Control Signals in Sessions]]'''
+
*'''[[How to Use Driver Setup Rule]]'''
+
*'''[[How to Use Message Popup Rule]]'''
+
*'''[[How to Use Message Popup Rule (Applications)]]'''
+
*'''[[How to Use Navigation Point Rules]]'''
+
*'''[[How to Use Navigation Point Rules (Applications)]]'''
+
*'''[[How to Use Parent and Child Rules]]'''
+
*'''[[How to Use Track Triggers]]'''
+
*'''[[Parent Rule List|List of Parent Rules]]'''
+
</div>
+
  
 
[[Category:How-to guides]]
 
[[Category:How-to guides]]

Revision as of 09:26, 21 April 2019

The information in this Wiki Page applies to both TANE and TRS19.

Contents


The screenshots shown below give examples of how variables can be used to control the operation of a session.

Example 1: Random Passenger Stop

Binoculars.PNG 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.

RandomLogic.jpg

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".

Conditions.PNG 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.
VariableRandom.jpg
Setting the random variable stopID


RulesWiki.PNG Rules Used:

In addition to those described in the Preconditions above:-

VariableCheck.jpg
Checking the variable stopID for the first stopping place


Screenshot.PNG Session Editor Screenshot:

AppRandomStop1.jpg


Explanation.PNG 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.


Example 2: Event Counter and Message Selection

Binoculars.PNG 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.

Conditions.PNG 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.


RulesWiki.PNG Rules Used:

DriverSchedule.jpg
Using the Driver Schedule Rule to halt the train


Screenshot.PNG Session Editor Screenshot:

VariableSPADWarnings.jpg


Explanation.PNG 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.

Lines 9 and 10 are then repeated with variations as shown. If more than 5 SPADs occur, then no further 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

Binoculars.PNG 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.

Conditions.PNG Preconditions:

  • A variable, ConsistCount is initially set to "0".


RulesWiki.PNG Rules Used:


Screenshot.PNG Session Editor Screenshot:

VariableConsistCounter.JPG


Explanation.PNG 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

Binoculars.PNG 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.

Conditions.PNG 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.


RulesWiki.PNG Rules Used:


Screenshot.PNG Session Editor Screenshot:

VariableTrainTrigger.JPG


Explanation.PNG 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.



Trainz Wiki

TrainzWiki.png

More Tutorials and Guides to Using Trainz

Personal tools