Text macro processing and conditional timetable input

You can customize your Timetable file by using conditional evaluations to base actions on conditions. Commonly known as "if/then" statements, conditional evaluations ask "what if," the operative part of the evaluation being "if" and then assign an action based on that "if." Additionally there is a text macro processing built in the input process of the timetable files, allowing concise formulation of some repetitive activity.

The syntax of the conditional evaluations is as follows:

{ ''<Condition>'' ? ''<true_part>'' ? ''<false_part>'' }

The conditions are evaluated first, and only the lines or line parts passed through the conditional evaluation will be analyzed and acted upon. You can modify any element of a Timetable file (commands, Movements, single parameters, vehicle names, modification commands) with these conditional expressions - the processing happens before any other activity, when the timetable file is read in, you can think of it as a distinct first pass of reading the timetable files. The condiditions mostly depend on the options, the user can set in the Options menu of the configuration window.

The configuration options must be referenced in the first few lines of the Timetable file by using the $OPT commands ( or setting them in the timetable file by the $SET command). The value of these options (selected or unselected) can then be choosen from the Traffic Configuration window using the Options menu commands. All the $OPT commands have to be in a single Timetable file, but that file may be either the main timetable file (selected in the configuration window), or one invoked by an $INCLUDE or $REQUIRE directive.

Individual configuration options can be linked together to create combinations of their outcomes. The linking process is similar to an algebraic equation, see the chapter Textprocessing Expressions.

The second question mark and the <false_part> parameter are optional, the <true_part> can be empty. Individual parts of the expression can be nested inside one another. For example: {Norway?E116|E117{Diesel?|Di6}} . If both options "Norway" and "Diesel" are checked in the option menu, than this snippet can choose from 3 types of engines, when Diesel is not checked, than from 2 engine types, and if "Norway" is off, than nothing results.

The "conditional evaluations" described here and the "conditional modifiers" controlled by criteria are completely different things. The conditional modifiers ( [<Condition>!<Command>:...] or [< <Command>:...]) base their outcome on the existence of criteria modifiers in the train expressions. In the Timetable file you can choose among the possibilities (to obey a modifier or not) which you defined in macro definitions elsewhere in the same Timetable file, in an included Timetable file or in the Stock List. In addition, you can select among the possibilities based on the actual direction of the trains - which can be the result of a random decision made by the computer. The conditional modifiers help to define the vehicles in general: with or without smoke, with or without load, which pictures are used for vehicles travelling left or right (or by mirroring a single vehicle picture or only certain parts of it).

On the contrary, the conditional evaluation ( { <condition> ? <true_part> ? <false_part> } ) based on the options relies on the decision of the human user - as the options can be set and cleared in the program's Configuration menu. A conditional modifier can behave differently during each screensaver run as its definition is based on the actual environment - that is, which context the vehicle macro is invoked. The same conditional evaluation behaves the same way in every run because the value of the options is analyzed at the start of the program and only the parts of the Timetable file will acted upon that fulfill the conditions in the { ? } constructs.

The conditional evaluation happens during reading the timetable files: the parts, which are selected to omit, won't be read in at all.

WTraffic understands all types of conditional expressions, but the conditional evaluation { ? ? } has practically no relevance. In case of Traffic, a single user selects the options, and the timetable file is read - the conditions are evaluated and the corresponding texts are selected, processed, others are omitted, so everything is already choosen, when the timetable will be read. In case of WTraffic the whole timetable file have to be read, as all the users utilize the same server, the same preprocessed, stored timetable. Conditional processing have to be done "on the fly", not when storing the trains, movements, directives, but when retrieving and using them.

The most important means for selecting Timetable parts to run in WTraffic is naming the sections, as in WTraffic the user (webpage author) can choose, which segmentation directive should behave as the top level section.