Rail3D*

   

 

Train



On this page…

  1. 1 Entry Points
    1. 1.1 Train Dynamics Functions
  2. 2 Functions

1 Entry Points

OnTimer()

Function is called every second of simulation time.

  • Object “Train” is automatically declared and may be used to access the current train object.
OnFrame()

From build 102.3.1

Function is called every frame of the simulation. This is a very low-level, high priority call so the minimum of script code should be applied to this call unless you want to seriously impact the frame rate.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • Variable “Secs” is automatically declared and gives the elasped time since the last frame.
OnSignal()

Function is called when train passes a signal.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • Object “Signal” is also declared and may be used to access the signal in question.
OnLocation()

Function is called when a train location (the stored location string) changes. This can occur with stops and reverses as well as with location features.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • If string “Location” is declared in the script it will be set to the location name text.

Note that the function may be called multiple times for each location/stop/reverse feature.

OnStop()

Function is called when a train stops at a stop.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • If string “Location” is declared in the script it will be set to the location name text.
OnReverse()

Function is called when a train reverses at a reverse feature.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • If string “Location” is declared in the script it will be set to the location name text.

The script function is called after the normal reverse code, so the script is able to modify route names, timing etc.

OnUncouple()

Function is called when a train uncouples.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • If string “Location” is declared in the script it will be set to the location name text.
OnCouple()

Function is called when a train couples.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • If string “Location” is declared in the script it will be set to the location name text.
SetControls()

Function is called to allow the script to “drive” the train and set the position of the power and brake controls etc.

  • Object “Train” is automatically declared and may be used to access the current train object.
OnCanShunt()

Function is called when the train passes a “Shunt” track marker.

  • Object “Train” is automatically declared and may be used to access the current train object.
  • If string “Location” is declared in the script it will be set to the location name text.
OnStuck()

Function is called when the train is “stuck” (Stuck is defined as held (eg by signal) for more than 120 seconds).

  • Object “Train” is automatically declared and may be used to access the current train object.
  • If string “Location” is declared in the script it will be set to the location name text.

1.1 Train Dynamics Functions

AccelerationForce()
BrakeForce()
DragForce()

These functions are for developing train dynamics algorithms and may be used to model specific traction characteristics.

Two train variables are passed to the script:

  • Train represents the specific vehicle the script is being called for.
  • Lead represents the leading vehicle of the train - the script needs to use this variable to access the control positions.

See also Vehicle Dynamics and Regenerative Electric

2 Functions

A train object represents a Rail3D ctrain object - note that this actually corresponds to a single vehicle (and usually in a script will represent the leading vehicle of a train).

Train++
Train--

Moves variable to next vehicle in the train (++) or previous vehicle (—). Returns null if no next/previous vehicle.

float GetSpeed()

returns current speed of the train in mps (metres per second)

int GetControl( int Controller)

returns current value of the specified controller in % (range 0 to 100).

  • Controller 0 represents the power control
  • Controller 1 represent the brake control.

It is intended to add additional controllers, eg steam loco cut-off, loco brake / train brake etc It is intended to define constants so that it will be possible to write (for example) GetControl(power);

See also Vehicle Dynamics

 SetControl(int Controller,float position);

Sets the position of the specified controller. Note that this is only relevant within a trains SetControls() function. It will work otherwise, but the computer default control will overwrite the change fairly quickly.

See also Vehicle Dynamics

int GetParam( int ParamNumber)

returns current value of the specified parameter

See also Vehicle Dynamics

 SetParam(int ParamNumber,float value);

Sets the value of the specified parameter

See also Vehicle Dynamics

void PlaySound(string WaveName)

Plays the wavefile specified by the string expression. The wavefile is looped and calling this function disables the program’s built in sound selection code. Note that the function should only be called when the wave changes since calling this function resets the wave to the beginning.

It is intended to add additional parameter to the function to specify a looped sound or a one-off sound.

string GetType(void)

Returns the stock type of the train vehicle.

void SetType(string)

Changes the type of the train item.

string GetRoute(void)

Returns the train route name

void SetRoute(string)

Sets the train route parameter.

void GetDestinationIndicator(string)

Retrieves the trains destination indicator string.

void SetDestinationIndicator(string)

Sets the train’s destination indicator (if fitted).

int GetStartTime()
void SetStartTime(int h,int m)

Retrieves the current start time in minutes (=60*h+m), or sets the train’s start time hours and minutes.

void QueryTimetable()

Makes a stopped train query or requery it’s timetable and possibly set a new start time.

string GetNumber(void)

returns the train number (lead vehicle number)

float GetLimit(void)

Returns the trains current speed limit in mps.

void SetLimit(float l);

Sets a new speed limit for the train, or clears the speed limit (l=0)

float GetMax(void)

Returns the maximum speed of the entire train as set in the Edit Train dialog.

float GetStockMax(void)

Returns the maximum allowed speed of the train/vehicle as set in the model file.

float GetStockTE(void)

Returns the available tractive effort of the entire train.

float GetStoppedCount(void)

Returns the number of seconds the train has been stopped (eg at signal).

float IsStuck(void)

Returns 1 if the train is “stuck” (ie held for more than 120 seconds)

void SetLimitAt(float l,float a,float y);

Sets a new speed limit for the train at a specified position ahead.

Bool IsFollowed(void)

Returns true if the train in question is the current user tracked train.

void SetPans(bool b1,bool b2);

Sets the state of the pantograph(s) up/down. Set b1 true to raise front pantograph, false to lower front pantograph. b2 controls the rear pantograph if present.

nb, at time of writing the definition of “Front pantograph” may depend on whether the item is reversed or not: it is intended to resolve this.

int GetLength(void);

Returns the length of the train in number of vehicles.

float GetMetres(void);

Returns the length of the train in metres.

bool GetDOS(void);

returns true if the train is in dos mode.

float GetDOSDistance(void);

returns the distance ahead (in metres) that the line is clear.

float GetTargetDistance(void);

returns the distance to the next speed change (or stop)

float GetTargetSpeed(void);

returns the target speed at the next speed change

void DeleteFollowing(void);

Uncouples and deletes trailing vehicles.

void Append(string Type);

Adds a new vehicle of the type specified to the end of the train.

??? GetPropelStock(void);

No description available — would anyone like to provide one?

void SetPropelStock(void);

Sets a train to propel stock on couple.

void Divide(int Position)

Causes the train to Divide after specified vehicle number. No apparent mechanism available to change front/rear portions’ route names.

void Reverse(void)

Causes the train to reverse.

void PassSignalAtDanger(void)

Authorises train to pass signal at danger.

void StartNow(void)

Starts the train immediatly



import