Rail3D*


 

Basic Syntax



General and Syntax

Syntax is generally C++ / Javascript in style.

  • A statement is terminated by ; or enclosed in braces {}
  • The compiler is not as tolerant of white-space as a true C compiler and white-space should not be allowed within statements or expressions.
  • Blank lines and indented lines are encouraged to aid readability.
  • Comment lines may be included: comment lines start with //
  • File extension .cpp is recommended

Compilation

Scripts are “semi-compiled” – that is the script is parsed and compiled during load time into an internal structure which is then interpreted at run time. This is designed to minimize computation required during run-time execution.

Performance

Scripts are resource intensive – they use a lot of memory and consume significant processing time. Therefore scripts should only be used for special cases, or for development of algorithms that will then be coded into the man program.

Adding scripts to Rail3D

A “run-once” script acting on the layout as a whole (e.g. to automate tracklaying) can be launched from the Tools menu in Rail3D. Scripts adding extra functionality to e.g. trains or signals can be added to a model at design time, or to an individual object in a layout.

Adding scripts to models

Scripts are added to Rail3D objects or models by including scripts in the model definition files in one of two ways:

  • A script block, enclosed by <script> script>, in the model file.
  • Including a script file using includescript “script file”

Included files are located by searching 1) the folder containing the model file 2) the rail3d\scripts folder.

Adding scripts to individual objects

Scripts may also be applied to individual objects (signals) using the “edit script” button on the object dialog. The object script is applied after the generic model scripts and duplicate functions (except init) override any functions already defined.

For example:

Model Script (in .sig file)

Init()
{
<< CODE A >>
}

OnTrain()
{
<< CODE B>>
}

Object Script (applied to individual object)

Init()
{
<< CODE C >>
}

OnTrain()
{
<< CODE D>>
}

Code applies as follows: For general signal of the type: code A is executed when the model is loaded code B is executed whenever a train passes the signal

For a signal with the additional object script: code A is executed when the model is loaded followed by code C code D is executed whenever a train passes the signal (code D overrides code B)



import