Session Variable and Mission Code

rmdk

New member
Was wondering what session variables and mission code do? And how they do it?

Are there any tutorials?

Russell
 
Hi.

Session variables are a N3V standard feature enabling to define, modify and test variables global to the session level (shared between all trains) referenced by their name. It is implemented as a standard N3V library available to any scripts. And there are some rules and driver commands to use these variables.
In the rules, you have Variable Check to check a value in a variable and have some conditional daughter rules execution depending on the variable value. Variable modify enables to alter a session variable value.
In the driver commands, Set S-variable and Wait S-variable enables a train schedule to alter a session variable or to wait for a specific value to be set in a session variable.

Extended Session Variables is another library that extends the standard N3V session variable features by offering also session variables linked to train. There are currently no rules or driver commands to use extended session variables, but the library is used internally by some rules and driver commands to share data between themselves.

Mission Code is a rule (Mission code Manager) that may be used for automatic path selection on a route using enhanced interlocking towers. It enables to assign a mission code (a string choosen in a user defined set of strings) to a train and to route the train at each enhanced interlocking tower path entry signal based on the current train mission code. Mission code needs some time to be fully understood, but is very powerfull to manage trains routing in a complex route offering a lot of possible paths. Mission Code Manager has some documentation on the wiki. You can also find the wiki page by searching Mission Code Manager via Google.

Hope this helps.
Regards.

Pierre.
 
Hi Russell

Links to the wiki pages for Mission codes and Interlocking Towers

http://online.ts2009.com/mediaWiki/index.php/Enhanced_Interlocking_Tower
http://online.ts2009.com/mediaWiki/index.php/Enhanced_Interlocking_Tower_Manager_Rule
http://online.ts2009.com/mediaWiki/index.php/Enhanced_Interlocking_Tower_Tip_001
http://online.ts2009.com/mediaWiki/index.php/Mission_Code_Stops_and_TimeTables_Manager
http://online.ts2009.com/mediaWiki/index.php/MissionCodes_Manager

This is a very powerful system for routing trains but, as Pierre says, does have a learning curve. I have found it well worth the effort to learn it.

Using variables is also a very powerful method for controlling trains as it allows them to make decisions on the fly. I use them combined with mission codes to create fully automated random sessions. In addition to the driver commands mentioned by Pierre there are also some conditional commands created by trev999 that allow you to select the next set of driver commands depending on the value stored in a variable.

Some uses for these include a token system for controlling single line sections.
Combined with other rules they can allow an industry to call up a train when its stocks are getting depleted by monitoring its queue(s).
Controlling stock levels of loaded and empty wagons at industries.
Randomly selecting a route for a train to take when there is a choice of more than one.

These examples are just the tip of the iceberg and the use of variables is only limited by your imagination.

If you use variables you will need the Input Table rule which is built in and which allows you to set up the variables that you may wish to use in the session. Driver commands, all by trev999 and on the DLS, are:-

"Insert buff label","Jump to Label","Set S-Variable","Skip if Session-variable" and "Wait Until S-variable V3".

I hope that this is of some use to you.

Regards

Brian
 
Thanks Pierre and Brian.

Sounds like there will be some learning to do.

I think the 'variable' is probably the way to go.

What I am trying to do is divert a train to a waiting point if the station or section of track is already occupied. Do you think this would be able to be achieved with the 'Variables'?

Russell
 
Hi Russell

You can achieve this with either variables or mission codes depending on the circumstances. With mission codes you can allocate path priorities between 1 and 3 to paths that have the same mission code and by using track circuit blocks to indicate if a section is occupied or not. The train will try to allocate the priority 1 path first followed by the priority 2 and then priority 3 last. It all very much depends on the circumstances and mission codes may not work as expected in all cases.

Pierre has a demo route on the DLS which illustrates how ITs, track circuit blocks and mission codes all interact but make sure you get the version for whichever build of TANE you are using.

With variables you would allocate a variable to indicate if the section of track is clear or not. As a train approaches the station/yard it will check the value in the variable. If it is 0 this indicates that the track is clear and the train will set the variable to one followed by setting the path or driving to the required track. However if the variable is set to 1 it indicates that the track is occupied and the train will then execute alternative commands to either direct it to a holding area or to wait until the track is clear.

If you wanted to put the train into a loop when the track is occupied for example and then drive to the track when it was vacant, then the commands to do this would be something like this:-

Skip to label 1 if var=0 (track is clear, next 2 commands not executed)
Drive to trackmark in loop (track is occupied)
Wait until var=0
Label 1
Set var=1
Drive to trackmark at destination
Other commands
Train leaves track
Set var=0

If using ITs then you would need to set the paths at the appropriate places and use the Autodrive command.

I would put this block of commands into the Schedule Library so that it can be inserted into the schedule of any train that needs it with one Copy command. This has the benefit that once it has been proven to work correctly it avoids risking errors when re-entering the commands into other schedules.

Quite often I use a mixture of mission codes and variables for this type of thing, again depending on the situation.

One thing to remember is that you have to get the logic correct otherwise you can get unexpected results. If I am creating something new and fairly complex then I will use a flowchart program to get an idea of which commands should go where. This tends to indicate the obvious pitfalls but it can still take some time to debug once you have the commands in trainz and test the session.



Regards

Brian
 
Is there an authoritative list of all of the commands as shown in the above example? As an example - Drive to track mark at destination - is this an instruction or a comment?

There seems to be some info on this, and other complex areas of pseudo programming, but no comprehensive construction tying everything together with good underlying detail.
Dick
 
Hi Dick

This was an illustration of how to approach this issue. I did it this way because different people often use alternative methods to get the same result such as "Drive to Trackmark", "Navigate to Trackmark" or path setting rules and driver commands followed by an "Autodrive" command which will all get a train to its destination. If not using ITs then I would use the "Drive to/via Trackmark" commands as Navigate to/via will look for alternative paths if the shortest one is blocked which could lead to undesirable results.

It was more an illustration of the logic needed to achieve what the OP was trying to do. Personally I use ITs and the "Autodrive" command in my sessions as it takes the route planning away from the AI and gives me more consistent results. Before TANE I used the SCS2013 rule to program sessions in TS12 but unfortunately that does not work in TANE.

By authoritative list do you mean the exact commands that I would use in the example above or a list of all commands generally?

Regards

Brian
 
Thanks to all above for their interest in helping me. I have been busy at work and haven't had a real good go at getting this working for me. I think I understand how it should work, but need some advice. Where and how (syntax) do I enter info to start to get this up and running?
 
Back
Top