Using Context with Trainzscript
- Context is a freeware programmer's editor which can be downloaded from contexteditor.org/downloads/.
- Highlighters for script files and for config.txt files can be downloaded by Clicking Here These are not essential for TRS2006 but are needed for TS2009 onwards. They show keywords, text strings and numbers in different colours and help to show where there might be missing quote marks and other problems with your code. A highlighter for config.txt files is included.
- Install the program and copy the highlighter files to \Program Files\Context\Highlighters.
- To integrate the compiler select Option\Environment Options from Context's menu and then select the Execute Keys tab.
- Click on Add and enter the file extension gs
- In the box at the top select one of the function keys and make these entries:
- Click OK to close the dialogue.
- Close Context.
- Create a new file called compile2006.bat in C:\Program Files\Auran\ (use whatever name and location you prefer)
- Add this text to the batch file, you may need to modify paths or filenames:
@echo off set gsc="C:\Program Files\Auran\TRS2006\Bin" set include="C:\Program Files\Auran\TRS2006\Scripts" %gsc%\gsc.exe %1 -i%include% -pc:\windows\temp set gsc= set include= pause
- Reopen Context and load a script file.
- Press F11, your script file will be saved and then checked by the compiler, if all has gone well you will see this:
- If there are any problems with the script details will be given together with the line number of the error.
- Interpreting these can be something of a black art, don't worry it will become easier as time passes.
Compiling in Context with TrainzUtil.exe for TS2009, TS2010, and TS12
TrainzUtil.exe is used to compile scripts in TS2009 onwards.
Set up a Context execute key as follows:
1. Open a trainz script in Context. You must have a Trainz Script highlighter file installed. 2. Call up the execute keys setup by clicking on 'Options/Environment Options' in the main menu. 3. Click on the 'Execute Keys' tab to get the execute keys set-up window. The window is the same as the one illustrated above. 4. Click on a 'User exec key' (eg F10) 5. Assuming you have TS2010, put the following string, or equivalent for your installation, into the 'Execute' box (including the quote signs) "C:\Program Files\Auran\TS2010\bin\TrainzUtil.exe" 6. Put the following into the 'Start in' box (including the quote signs) "%p" 7. Put the following, or equivalent for your installation, into the 'Parameters' box compile %n -i"c:\Program Files\Auran\TS2010\Scripts" -pC:\temp 8. Turn on the 'Capture console output'. 9. In the 'Compiler output parser rule' put the following %f(%l) 10. Click on the 'Apply' button to save.
Your setup for TS2010 compiling should look as below:-
Now when you press F10 the script should be compiled and error checked by TrainzUtil for TS2010.
Compiling in Context with TrainzUtil.exe for Trainz A New Era
TrainzUtil.exe can be used to syntax-check scripts in T:ANE.
Please note that the T:ANE launch window must be open for this to work, and that you must set the advanced debugging options as below.
Also please note that I have T:ANE installed on E: drive (a solid state drive), and that I have moved my user data to that drive. The settings below should work for the default locations of the data.
Additionally note that this setup uses an undocumented feature for trainzutil.exe for T:ANE. The compile feature has been unsupported for some time now. Scripts are now checked by the validation process.
Set up a Context execute key as follows:
1. Open a T:ANE trainz script in Context. You must have a Trainz Script highlighter file installed. 2. Call up the execute keys setup by clicking on 'Options/Environment Options' in the main menu. 3. Click on the 'Execute Keys' tab to get the execute keys set-up window. The window is the same as the one illustrated above. 4. Click on a 'User exec key' (eg F11) 5. Assuming you have T:ANE, put the following string, or equivalent for your installation, into the 'Execute' box (including the quote signs) "E:\N3V Games\Trainz A New Era\TrainzUtil.exe" 6. Put the following into the 'Start in' box (including the quote signs) "%p" 7. Put the following, or equivalent for your installation, into the 'Parameters' box compile %n -i"E:\N3V Games\Trainz A New Era\resources\Scripts" -pC:\temp 8. Turn on the 'Capture console output'. 9. In the 'Compiler output parser rule' put the following %f(%l) 10. Click on the 'Apply' button to save.
Now when you press F11 the script should be syntax-checked by TrainzUtil for T:ANE.
The image below shows a T:ANE trainz script in ConTEXT.
Note the different colours for keywords, text, numbers and comments.
The script has a deliberate error in line 93 to illustrate how the output from the syntax-check is displayed.