| Train Director 3 - Scripts |
English -
Italiano
|
Version 3.3 of Train Director allows scenarios authors to specifty both the behavior and the appearance of individual signals. The introduction of this functionality allows the display of the aspects of the signals for advance signals, advance and protection signals, for signals specifying a reduction in speed based on the selected itinerary and so on. Moreover, it is now possible to display the signal aspects used by different railroad administrations. All of this is implemented by using text files that are indipendent from the scenario. These files describe the icons to use, the behavior of the train when approaching the signal, and how to decide the aspect of the signal based on line conditions. These text files are called "Train Director Scripts", or simply ".tds files". A .tds file can be associated to one or more signals. The association is specified through the "Signal Properties" dialog. ![]()
This is an example of a .tds file:
# One light signal (red,yellow,green) Let's describe each section of the file: CommentsThe first row of the file is a comment, and shows the type of the signal: # One light signal (red,yellow,green) All characters from the # included to the end of the row will be ignored by the program. Comments are completely optional, so you don't have to use them. However their presence is a big help to other authors who want to better understand the logic of the file and to which signal to apply it to. AspectsThe next section describes the various aspects that the signal can show:
Aspect: red The name of the aspect is indicated by the "Aspect:" rows. In this case we have 3 aspects: "red", "yellow", and "green". For each aspect, it's necessary to specify the icon to display when the signal is in the corresponding state "for each of the 4 directions", east, west, north, south. If the scenario does not use signals directed to north or south, the corresponding directions can be omitted. In this page's examples we'll only use the east direction, assuming that the author will have to specify the other directions as well. It is also possible to specify more than one icon per each direction. The various icons will be displayed in sequence, going back to the first icon after the last one has been displayed. This feature allows to "animate" the signal, for example to show flashing signals. In addition to the icon file, every aspect has associated an action, specified in the "Action:" rows. This action will be executed when a train is traveling in the track section preceding the signal. The possible actions are:
With these simple instruction it's possible to create a number of cases, so that one can describe the most common combinations. The following sections tell to the program when to change the aspect of the signal. Events and ConditionsObviously, a signal must change its aspect when certain conditions on the layout occur. These conditions can be generated both by the player and by trains movement. Let's consider for each conditions which actions can be applied. OnInit : when the scenario is loadedThe actions associated with "OnInit:" are executed when the scenario is opened the first time. Typically the associated action is the definition of the initial aspect of the signal (usually red). OnInit: Let's examine in greater detail the syntax to use in this section of the .tds file. The section starts with the event that we are describing, that is "OnInit:". After the name of the event, we specify a sequence of actions in the form of expressions. In this case, ".aspect = red" means "change the signal aspect according to the instructions in the "Aspect: red" section.". Assigning a name to the aspect tells Train Director to change the icon and the action associated with that signal, using the information specified in the corresponding "Aspect:" section. The use of the "dot" in ".aspect", indicates that we are referring to the signal associated with this .tds file. We'll see later how it's possible to refer to other signals. The section is always terminated by a row with the word "end". OnCleared : the user clears the signalWhen the user clicks on the signal's icon, if the following track section is clear, then Train Director will examine the instructions associated to the "OnCleared:" event to decide how to change the signal's aspect. In this case, the actions to carry out are more complex: OnCleared: As you can see, it's possible to query if certain conditions are valid by using the "if" word. In the first row we are checking whether the current aspect of the signal is red ("if .aspect = red"). If it isn't, the program ignores all actions included between the "if" row and the corresponding "end". If instead the condition is true, the program continues with the execution of the next row. In this example, we check what is the aspect of the next signal after the current one ("if next.aspect = xxxx"). As you can see, the use if the word "next" before the word ".aspect" tells Train Director to "look ahead" in the track section protected by the signal. It is also possible to look ahead 2 or 3 track sections, by simply concatenating multiple "next" words, as in "next.next.aspect". Therefore, if the next signal is red ("if next.aspect = red"), then the current signal should display an approach to stop aspect; to do this, we change its aspect to yellow (".aspect = yellow"). If instead the next signal is not red, Train Director will examine the actions associated to the "else" word, in this case by changing the aspect of the signal to green (".aspect = green"). Note how to each "if" always corresponds an "end" (2 ifs, 2 ends plus the end-of-section "end"). The convention to shift to the right the instruction related to each "if" helps in understanding which condition controls the execution of those instructions. OnUpdate : another signal has changed aspectWhen another signal on the layout has changed aspect, Train Director will execute the instructions associated with the "OnUpdate:" section. This allows changing the aspect of a signal when the signal in the controlled track section changes aspect. In our example:
OnUpdate: The logic is as follows: if the current signal is red, no action is performed; the row with the "return" word tells Train Director to ignore all the following instructions for this signal. If the current signal is not red, then we need to look at the next signal to verify its aspect ("if next.aspect = xxxx"). If the next signal has become red, then we need to change the aspect of the current signal to yellow (".aspect = yellow"). If the next signal is not red, then we need to change the aspect of the current signal to green (".aspect = green").
By specifying the signal's behavior in the way just described allows the representation of many combinations specified in the "Regolamento Segnali" of Trenitalia, and hopefully of other international railroad administrations. In the following page we present more complex cases.
|
|