General Introduction
In scripting, there are some predefined terms that can be used. Each action contains at least one action, which in turn can have multiple commands.
Note: Scripting allows for many possibilities, but it is worth saving functional intermediate states, as things can quickly stop working as intended. If this happens, simply reload the saved config (cfg.xml) back onto the module.
Attributes and Their Meaning
- value mostly serves as an operator
- pinID: ID of a pin
- ms: millisecond time specification
- intValue
- msInterval
- group: grouping in the interface (control panel)
- type determines whether it is a number, a character, or a color
- actionID: ID (name) of a function, trigger, or timer
- varID: use of the value of a parameter or other action
Valid Operators for Value
For setIO:
- greater >
- smaller <
- equal =
- unequal - random #
- multiply - set red green blue R,G,B - random R,G,B r,g,b For set: - random # - multiply
- greater >
- smaller <
- equal =
- unequal - subtract (can be used when creating a kind of for loop) -
- add (can be used when creating a kind of for loop) +
Each script window has four buttons on the side for operation:
Commands
The commands apply to all actions and are always configured the same way. To add a new command, click the + button in the script window.
If a pin has been set, the settings on the right change again. A dropdown menu allows selecting one of the pins. In the next field, an advanced option can be chosen. After that, the value can be taken from a variable (parameter), a color picker, or entered as an int value to specify the color.
Caution: Only parameters with the correct data type are displayed.
If a set command has been used, the dropdown menu shows all available parameters. If none are present, a new one must be created (see Creating a New Parameter ). After that, the parameter options can be specified. Here too, a value can be read from a variable (parameter) or entered manually. Parameters are only displayed if they have the correct data type.
For a call, a function is selected via the dropdown menu. The next menu decides which state of the selected function to access. Finally, a value can be passed to the desired state. Both influence the states in a specific way.
TODO: Table of different states
In an if statement, a triggering condition is selected here—a variable. Next, the operation is chosen. As the third step, the value to compare is entered via a parameter or a number. The trigger is an exception, as the third step expects a character or letter instead of a number.
In an else if statement, a triggering condition is selected here—a variable. Next, the operation is chosen. As the third step, the value to compare is entered via a parameter or a number. The trigger is an exception, as the third step expects a character or letter instead of a number.
Note:
- The "call" and "if" commands represent nesting. If the nesting of a script exceeds 10 levels , it will be aborted with an error starting from CTC-App 4.40 and firmware 20250627.
- The processing of scripts and state changes is documented in the "4242Action-Log.csv4242" file starting from CTC-App 4.40. This file is located in the data folder of the CTC-App and is recreated (overwriting old content) each time the CTC-App starts. It can be viewed conveniently with LibreOffice Calc (Excel may work but is not guaranteed).
Note:
- delay is deprecated, though still visible when connecting to an old module.
Creating a New Parameter
To create a new parameter, click the plus button in the upper table.
Enter the name of the new parameter. Then, a value and its type can be specified. Finally, confirm with OK, and the new parameter can be used.
Functions
Essentially, every product has at least one predefined function; otherwise, it wouldn't do anything. However, you can change or extend these functions using scripts. To do this, you must first open the script window.
In the upper part of the window, basic details such as the function name, its group (default: signal tower), type, and default state are specified.
Below that is the actual script window where programming takes place. If a function is selected, clicking the Add button allows adding a state. If an existing state is selected, the same button can be used to add a command. Now, settings for the state appear on the right side.
First, you can specify under which character (letter) or number the state is addressed. Next, a name can be given to the state. Below that, a symbol can be assigned, which must have the same name as the state. Next to it, the position (pos) is specified. These two entries are visible as control elements in the app in the correct group. At the very bottom, DCC can be specified if control is desired via a digital control unit (tested with mc² control unit).
Timers
The timer plays a role whenever something needs to happen repeatedly.
Note: A timer always runs in the specified cycle. However, it can also be called as a single-shot, in which case it runs through exactly once.
In the upper part of the window, the product name with the "-tim" suffix is displayed. The default group is "hidden". Next, the type is specified, here as default script. Then, the timer cycle duration in milliseconds is specified (max 1000, limited by the interface). For a single shot, this value must be 0.
Below that is the actual script window where programming takes place. If the timer is selected, clicking the Add button allows adding nothing. If the time is selected, the same button can be used to add a command. Now, settings for the state appear on the right side.
First, you can specify under which character, letter, or number the state is addressed. Next, a name can be given to the state. Below that, a symbol can be assigned, which must have the same name as the state. Next to it, the position (pos) is specified. These two entries are visible as control elements in the app in the correct group. At the very bottom, DCC can be specified if control is desired via a digital control unit (tested with mc² control unit).
Triggers
The trigger is used when one product should influence or trigger another, such as a beacon, signal, or distant signal.
In the upper part of the window, the product name with the "-trg" suffix is displayed. The default group is "Trigger". Next, the trigger source is selected. This can be a beacon or another signal. In the (MAC) window, a locomotive can be directly assigned that triggers a beacon. Otherwise, a beacon is always triggered when something passes over it. Then, the type is specified, with the default being charVal. Finally, a source and a default value can be specified, though both are empty by default.
Note: Triggers do not fire immediately but in an unknown order, so ensure this does not cause issues.