Receipe: Timetables in scripts

  • Since the procedures and functions that are available around the topic "Schedules and dispatching in the script system" are quite extensive and special, we present here some examples of how to use them.

    1 General

    In the following procedures and functions no consideration is taken in the sense of the simplicity on special efficiency, since primarily at the example is to be explained, how the functions work. Therefore, at the end of each example it is generally suggested how the procedure can also be made more efficient.

    2 Preliminary work

    For various functions, the name of the AVLC server is required to which the AVLC on-board unit is to log on. This information is stored in the basic PIS file. Since it does not change from then on, it makes sense to store it in a variable. This should not be a "PUBLIC_VARS" variable, but one that is simply declared outside the procedures.

    The variable should not be written in the Initialize procedure, but once during the first run of SimStep:

    3 Routes (not times)

    3.1 Where is the vehicle located on a particular route?

    Assumed: The user has entered the line and route in the AVLC on-board unit and the system is now to determine whether and where the vehicle is on the route. The so-called "section" is returned. Here, counting is started at the start stop with number 0 and then the section between the stations and the stations themselves are counted alternately:

    0: at the departure station

    1: between the first and second station

    2: at the second station

    3: between the second and third station


    It is more efficient if the wayIndex is only recalculated when linieStr and/or routeStr change or when an input is made that potentially leads to a different wayIndex.

    3.2 What is the name of the station where vehicle is located?

    The following function returns the PIS ID that was entered in the configuration of the stations in the MapEditor. If there is one for the specific track, then this is returned. If there is only one for the entire station, then this is returned, otherwise the internal name of the station.

    Again, the line and route numbers entered into the device must be passed to the function, as in the previous example. If no station was found, an empty string is returned:

    Here, too, it would be more efficient if the wayindex were determined only when something changes in the line/route combination. But also the section has to be updated at least once per run - if at all so often, a "loose" interval is also sufficient here.

    3.3 Distance between two stations along a route

    This function can be used to determine - completely independently of where the vehicle is currently located! - determine how far any two stations are from each other (measured along the route).

    It is important here that the stations are searched for using the PIS ID stored in the MapEditor. If the route runs over a track that has its own PIS ID that differs from the station, then that ID is used. If the route runs over several stations (tracks) with the same PIS ID, the first station is used.

    4 Trips (with times)

    4.1 Convert hours and minutes to string

    4.2 Show trips of a tour

    For the following function, imagine that you first enter the line and course and then use the arrow keys to switch through the available journeys, which are then displayed in a text field with the first departure time, start and end station. index is the number, which is increased or decreased by 1 with the arrow keys.

    For the following function, the system variables TimeOfDay and Date, both of which must be declared in the "PUBLIC_VARS" section.

    This example is full of inefficiencies, since all queries are made in one go. So, of course, the tour only has to be called up when the line and course change. Accordingly, the trip list only has to be updated then and the number of entries of this list can be written once into a global variable instead of into a function locale.

    5 to be continued...