Getting Started in TrainzScript

From TrainzOnline
(Difference between revisions)
Jump to: navigation, search
(Tutorials)
 
(6 intermediate revisions by 3 users not shown)
Line 17: Line 17:
  
 
==Tutorials==
 
==Tutorials==
The following are links to various tutorial pages available for TrainzScript, these have been updated for TS2012:
+
The following are links to various tutorial pages available for TrainzScript.  (Temporary notes: These were last updated to reflect TS12 standards and the base script libraries have changed significantly since mid TS19 versions.  Do not assume they will work in TS22.  They will be rewritten.)
  
 
'''For Beginners:'''<br>
 
'''For Beginners:'''<br>
Line 33: Line 33:
 
# [[Handling Name Effects.]]<br>
 
# [[Handling Name Effects.]]<br>
 
# [[Texture Replacement.]]<br>
 
# [[Texture Replacement.]]<br>
 +
# [[Prequel Blender to Trainz|NEW: Prequel for this tutorial series: Blender to Trainz (with the full script)]]
  
 
==Script Compilation Errors==
 
==Script Compilation Errors==
Line 40: Line 41:
 
Error: ''...parse error...in line xxx''<br>
 
Error: ''...parse error...in line xxx''<br>
 
Possible cause:  Perhaps the most common error found during compilation.  This means that the compiler was unable to continue because of format errors.  Usually the error will be on Trainzscript lines preceding the line number in the error.  Look for missing closing curly brackets ( } ), or invalid constructs.  The compiler always stops at the first error and errors later in the source file will not be identified.  This is why it is always best to add small amounts of code and then check for errors.<br><br>
 
Possible cause:  Perhaps the most common error found during compilation.  This means that the compiler was unable to continue because of format errors.  Usually the error will be on Trainzscript lines preceding the line number in the error.  Look for missing closing curly brackets ( } ), or invalid constructs.  The compiler always stops at the first error and errors later in the source file will not be identified.  This is why it is always best to add small amounts of code and then check for errors.<br><br>
 
[[Category:How-to guides| ]]
 

Latest revision as of 20:47, 10 April 2024

Contents

[edit] Script Usage

  • In Trainz SP3, script support was added to allow the creation of scripted scenarios (interactive activities.) While existing scenarios are still usable in TS2010, creation of these assets has not been supported by N3V since TRS2006 and future versions of Trainz will drop support for this asset kind entirely.
  • Scripts are used to make objects perform operations in reaction to events. For example a level crossing (grade crossing) can be made to operate as a train approaches it.
  • Rules are written as scripts, and these rules can be included in Driver sessions, effectively as the session's program elements.
  • Driver commands are written as scripts, and these can also be included in Driver sessions so as to give train drivers a series of operations to perform.


[edit] Creating and Editing Scripts, Tools to Use

  • Trainz scripts need to be included in your asset folder as plain text files with a *.gs file extension.
  • Compile-time errors in the script, including spelling or syntax errors, cause the parent asset to be flagged as erroneous by Content Manager.
  • Runtime errors won't be flagged up until you load a map which uses your asset or when you first place your asset on a map.
  • Although you can use Notepad to create and edit files and commit them directly to the game, it will quickly become frustrating having to run TRS to find that you have missed out a semicolon or closing quote.
  • Trainz also includes command-line error checking support through TrainzUtil for situations where the Content Manager GUI is inappropriate.
  • Editors which will help you to ensure that your scripts are correctly formatted are freely available, one such is Context and details of how to obtain it and set it up for Trainz are included at this page: Using Context with Trainzscript. Another such program is TextPad (http://www.textpad.com).

[edit] Tutorials

The following are links to various tutorial pages available for TrainzScript. (Temporary notes: These were last updated to reflect TS12 standards and the base script libraries have changed significantly since mid TS19 versions. Do not assume they will work in TS22. They will be rewritten.)

For Beginners:
A set of tutorials by Andi Smith which will take you through the steps involved in setting up a simple script on a scenery asset, starting with the traditional 'Hello World' and ending with the use of a Property Interface to deal with basic effects, including animation, sounds and texture replacement. The tutorials largely avoid object-oriented terms such as encapulation, inheritance and polymorphism, and instead try to concentrate on getting your scripts working as quickly and painlessly as possible.

  1. Hello World, Setting Up An Asset Script.
  2. Getting Information From the Game, Writing Your Own Methods.
  3. Talking to Yourself, Sending Messages.
  4. Saving and Restoring Data, Using Properties.
  5. Setting Up the Asset.
  6. Automating Animations.
  7. Handling Corona Effects.
  8. Playing Sounds.
  9. Hiding Meshes.
  10. Handling Name Effects.
  11. Texture Replacement.
  12. NEW: Prequel for this tutorial series: Blender to Trainz (with the full script)

[edit] Script Compilation Errors

The follow is a list of compilation errors and possible causes:

Error: Unable to link compiled script class.
Possible cause: The class name in the config.txt class tag is not found in the script identified in the script tag. Generally this is a misspelling.

Error: ...parse error...in line xxx
Possible cause: Perhaps the most common error found during compilation. This means that the compiler was unable to continue because of format errors. Usually the error will be on Trainzscript lines preceding the line number in the error. Look for missing closing curly brackets ( } ), or invalid constructs. The compiler always stops at the first error and errors later in the source file will not be identified. This is why it is always best to add small amounts of code and then check for errors.

Personal tools