Script Editor
The Script Editor is a dialog for developing train scripts, and watching them in action. It provides an editable text box with special features for script development, along with player buttons for playing, stopping, recording, and rewinding the script. As the script executes, the active line is highlighted in the text box, so you can follow along with the action.
To bring up a Script Editor, (a) select a train and choose Train > Script > Edit from the menu; (b) click the Edit Script button on the Scripts toolbar; (c) double-click a train script entry in the Scripts tab of Script Central.
Each train script has its own Script Editor window. If you have multiple scripts on your layout, you can have multiple windows showing the different actions in each. The dialog is modeless, so it remains up as you run the layout.
If there are multiple train scripts on the layout, then the buttons in each Script Editor work differently from the corresponding ones on the Script Toolbar. In the latter,Play, Stop, and Rewind apply to all scripts at once; in the Script Editor, buttons apply only to the script in the window.
Dialog controls:
The Script Editor is always working on a single script. If you bring it up on a train having no script, it creates an empty one for you to fill in.
Text box |
Editable box for script text. Highlight shows current line. Right-click for editing or Go To commands. |
Play |
Begin executing the script at the current line. |
Stop |
Stop the script and the train. If recording is in progress, stop it. |
Rewind | Reset to first line of script, restore train and switch positions to layout Rewind Point |
Record | Begin recording train moves, capturing them starting at the current line. |
Buttons | Apply: update scripts on layout (not saved permanently until layout save); OK: apply and dismiss; Cancel: dismiss without saving -- changes to Done after any save. |
Context Menu
The context menu in the Script Editor and other script windows gives access to standard editing commands, as shown here. In addition, the Script Editor provides an additional command:
Set Next Command Here is handy for debugging and development. Point to any line in the script, right-click and choose Set Next Command Here, and that line becomes highlighted -- the next to execute when you press Play.
This command is undoable. Undo goes back to the statement which was active before.
There is a catch. This feature lets you start at the script statement to be executed, but does not reposition the trains. It's up to you to make sure the trains are in suitable positions when you start playing the script.
Switch Shortcuts
As another convenience for script authors, you can insert text into the script window by choosing a command from a context menu on the layout. As long as the Script Editor is visible, and you are using the track or edit tool, then right-click a junction or switch and you get three new commands on the context menu:
Each of these commands inserts a bit of text at the position of the cursor in the text box. What is inserted depends on what you right-clicked:
Insert junction number |
Insert the number of the clicked junction. Need not be a switch. |
Insert throw here |
Insert a THROW statement with the junction number and its current position; for switches only |
Insert throw alternate |
Insert THROW plus junction number plus alternate position; for 2-way switches only |
This applies to the Junction Action Editor also, and to the script windows in Script Central -- whenever any of these is visible on screen, junction context menus can insert into it. If more than one is showing, the frontmost one gets the insert.