How to Use Variables in Sessions (Examples)

From TrainzOnline
Revision as of 22:25, 30 April 2018 by Pware (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 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 from 1 to 3. Each number representing one stop.
VariableRandom.jpg

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.

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

Rules Used:

Session Example:

AppRandomStop1.jpg

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?".
VariableCheck.jpg
  • 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 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.
Personal tools