The automatic code generator can save a great deal of time, but it does stunt your style somewhat. By inserting your own code alongside the automatically generated code your can expand your horizons considerably:
Drive some, or even all of your trains manually. Yes it does make sense to automate the trains and then run them manually! You can arrange manual driving but the automatic system slows and stops the train for you if you are going to run a red signal.
Automate some scenic detail such as crossing gates, or even day-night lighting cycles.
Give trains routes to follow
Add a manual control panel.
To insert your own code, you simply put it in the TDL file:
Long L1 - to L2 Long L2 - to L3 When L2.s>=TrainPresent DO gates=open |
OK, its a rather trivial example but it does show regular TCL in a TDL file. All inserted statements appear at the end of the auto-generated TCL file.
The following types of statement may be inserted:
When |
A conventional When statement |
WhenNT |
Same as When except that if logging is set to listing, this statement is NOT shown in the log. The NT flag puts Tracing control statements around the statement to suppress logging. This is useful for statements which are executed frequently and logging them would just fill up the file. |
While |
A conventional While statement |
WhileNT |
Same as While except this statement is log logged. See description of WhenNT for details. |
All the code of the statement must be on a single line. This is because the TDL file is based around records which are line based, whereas a TCL file takes little notice of line feeds. There is no limit on line length, but long lines can get difficult to read.
Variables and I/O can also be declared - useful if your extra code needs access to data and I/O not used by the automatic code. These use lines beginning:
Constants |
To add named constants to the 'Constants:' section |
Variables |
To add normal variables to the 'Variables:' section |
Sensors |
To add extra input lines to the 'Sensors:' section. These are added as they are defined in the TDL file, in the same way that all other sensor inputs are added so you have control over which pins on which stacks they are connected to. |
Controls |
To add extra output lines to the 'Controls:' section. As with sensors these are added as they are defined. |
The syntax is similar to that used in TCL files, but not quite the same. The items are space separated words instead of a comma separated list. This means you must not include spaces between a name and array brackets for example. Also the usual item name is included and currently ignored, so some sample code might look like:
# States that the siding can be in Constants - sManual=20 sDispatchRequested=21 sDispatching=22 Constants - sAuto=25 sCallIn=26 # 2 buttons Sensors - AutoMan~ CallDispatch~ # LEDs in the buttons Controls - ManualLed, DispatchLed # Handle startup When sState=0 DO sState=sManual # # Handle state change requests When sState=sAuto, AutoMan=TRUE, sButton=FALSE DO sState=sManualRequested, sButton=TRUE |
This is an extract of the code that handles the manual control panel in jax9.tdl - the file that controls the G-scale layout described in the MERG Summer 2007 journal.
Last updated 19/02/09
© Howard Amos. 2008-2009