The graphical event management with actions and conditions screen covers the most important areas of application in the automation of model railway layouts. However, there are situations where more control is required in processing events. For these special areas, 3D Train Studio supports the scripting language Lua.
The script language is fully integrated into the event management:
- Create any event.
- Click on <> in the middle area to open the script view.
Instead of the action list, a text window is now displayed in which you can enter the Lua commands. Tip: An existing action list is automatically converted to Lua when you switch to the script view. You can use this conversion as an introduction to programming with Lua.
Actions and Conditions
Lua scripts can be mixed with the predefined actions and conditions as desired, i.e. an event can be composed of predefined actions and conditions as well as Lua scripts:
- Click + in the Action List, then click Actions > Run Script to add a script to a list of existing actions.
- Click + and then click Conditions >Script Condition to program a single condition with Lua. The Lua script must return a Boolean to decide whether the condition applies (true) or not (false).
Different events often use common data and functions. In order to store these in a central location, a script can be defined in an event module. To do this, click on the + symbol> in the event management and select Script .
Each event module has its own script, whereby all the variables and functions defined there are available in the entire event management.
All commands supported by 3D Train Studio are documented in the automatic help (auto-completion). In addition, the following information can help with further questions and problems: