How to Use Variables in Sessions (Examples)
(Created page with "The screenshots shown below give an example of how a variable can be used to control the operation of a session. ==='''Random Stop Example'''=== '''The Scenario:''' In this...") |
(added "Event Counter and Message Selection Example") |
||
Line 1: | Line 1: | ||
− | The screenshots shown below give | + | The screenshots shown below give examples of how variables can be used to control the operation of a session. |
==='''Random Stop Example'''=== | ==='''Random Stop Example'''=== | ||
Line 8: | Line 8: | ||
'''Preconditions:''' | '''Preconditions:''' | ||
+ | |||
*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#Variable_Random_Rule|Variable Random Rule]]''' is used to create a variable with an integer random value from 1 to 3. Each number representing one stop. | + | *The '''[[Session_Rule_List_with_Parameters#Variable_Random_Rule|Variable Random Rule]]''' is used to create a variable with an integer random value, '''stopID''', from 1 to 3. Each number representing one stop. |
<table> | <table> | ||
<tr> | <tr> | ||
Line 26: | Line 27: | ||
If a stop is required then a predefined '''Navigation Point''' is shown to indicate the stopping place. | 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 | + | The same logic is repeated for the other two stations with '''stopID''' values of "2" and "3". |
'''Rules Used:''' | '''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. | ||
*'''[[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 display a predefined navigation point. | ||
*'''[[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. | ||
− | |||
− | |||
<table> | <table> | ||
Line 45: | Line 45: | ||
*'''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 | + | *'''Line 2: Variable Check''' The value stored in the variable '''stopID''' is tested "=1". |
<table> | <table> | ||
<tr> | <tr> | ||
Line 51: | Line 51: | ||
</tr> | </tr> | ||
</table> | </table> | ||
− | *The following 2 lines are executed only if | + | *The following 2 lines are executed only if '''stopID''' is '''equal to''' "1" |
**'''Line 3: Navigation Set Hide/Show''' Displays a navigation point showing the stopping location. | **'''Line 3: Navigation Set Hide/Show''' Displays a navigation point showing the stopping location. | ||
− | **'''Line 4: Message Popup''' Display the message window showing that a stop has to be made at Sandplace. | + | **'''Line 4: Message Popup''' (executed only if '''stopID''' is '''equal to''' "1") Display the message window showing that a stop has to be made at Sandplace. |
− | *'''Line 5: Variable Check''' The value stored in the variable | + | *'''Line 5: Variable Check''' The value stored in the variable '''stopID''' is tested "<>1". |
− | *Line 6 is executed only if | + | *Line 6 is executed only if '''stopID''' is '''not equal''' to "1". |
**'''Line 6: Message Popup''' Display the message window showing that no stop has to be made at Sandplace. | **'''Line 6: Message Popup''' Display the message window showing that no stop has to be made at Sandplace. | ||
+ | |||
+ | ==='''Event Counter and Message Selection Example'''=== | ||
+ | |||
+ | '''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 and reset by track triggers. | ||
+ | |||
+ | A variable, '''SPADCounter''', is used to count the SPAD events and is initially set at 0. | ||
+ | |||
+ | '''Rules Used:''' | ||
+ | |||
+ | *'''[[Session_Rule_List_with_Parameters#Signal_Passed_At_Danger_Rule|Signal Passed At Danger 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#Driver_Schedule_Rule|Driver Schedule Rule]]''' used to immediately stop the train. | ||
+ | *'''[[Session_Rule_List_with_Parameters#Simultaneous_List_Rule|Simultaneous List Rule]]''' to force all rules to run simultaneously for speed. | ||
+ | *'''[[Session_Rule_List_with_Parameters#Variable_Modify_Rule|Variable Modify Rule]]''' to alter the value held in a session variable. | ||
+ | *'''[[Session_Rule_List_with_Parameters#Message_Popup_Rule|Message Popup Rule]]''' to open a message window on the screen. | ||
+ | |||
+ | <table> | ||
+ | <tr> | ||
+ | <td>[[file:VariableSPADWarnings.jpg]]</td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | |||
+ | '''Example Explanation:''' | ||
+ | |||
+ | *'''Line 1: Signal Passed At Danger''' The event is triggered every time a specific user controlled driver 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 SPAD is processed. | ||
+ | *'''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. | ||
+ | <table> | ||
+ | <tr> | ||
+ | <td>[[file:DriverSchedule.jpg]]</td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | |||
+ | *'''Line 4: Variable Modify''' The value stored in the variable '''SetSPAD''' is increased by 1. | ||
+ | *'''Line 5: Simultaneous List''' This forces all the following Variable Check rules to be executed simultaneously. This is not strictly needed but without it ALL those rules will then be executed in order when only one of them actually needs to 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 rules are processed. | ||
+ | **'''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 rule is processed. | ||
+ | **'''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. |
Revision as of 15:11, 2 May 2018
The screenshots shown below give examples of how variables can be used to control the operation of a session.
Random Stop Example
The Scenario:
In this example, a random variable will be used to decide which one of 3 stations where a user controlled train will be requested to stop. 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:
- 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 Variable Random Rule is used to create a variable with an integer random value, stopID, from 1 to 3. Each number representing one stop.
Program Logic:
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".
Rules Used:
- Trigger Check Rule to trigger the decision and message event.
- Variable Check Rule to check the value held in a session variable.
- Navigation_Set_Hide/Show Rule to display a predefined navigation point.
- Message Popup Rule to open a message window on the screen.
Example Explanation:
- 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".
- The following 2 lines 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 (executed only if stopID is equal to "1") Display the 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 Display the message window showing that no stop has to be made at Sandplace.
Event Counter and Message Selection Example
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 and reset 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 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.
- Simultaneous List Rule to force all rules to run simultaneously for speed.
- Variable Modify Rule to alter the value held in a session variable.
- Message Popup Rule to open a message window on the screen.
Example Explanation:
- Line 1: Signal Passed At Danger The event is triggered every time a specific user controlled driver 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 SPAD is processed.
- 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 SetSPAD is increased by 1.
- Line 5: Simultaneous List This forces all the following Variable Check rules to be executed simultaneously. This is not strictly needed but without it ALL those rules will then be executed in order when only one of them actually needs to 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 rules are processed.
- 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 rule is processed.
- 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.