Keeps track of train information, and allows you to more easily obtain specific train information (Such as next station, destination station, whether the train is returning to depot or docked on a platform, etc.)
To access the underlying TrainWrapper provided by NTE, use the .train
variable.
This is the constructor for this object. This should be stored in your state
in the createTrain
function.
Parameters:
train
: Thetrain
parameter fromcreateTrain(ctx, state, train)
This updates the train data, you should call this in your renderTrain
function.
Parameters:
train
: Thetrain
parameter fromrenderTrain(ctx, state, train)
Return this train's next station, returns a Station. (stn.name to obtain the station number)
Parameters:
allRoute
: Whether to also consider stations outside the current running route.
This is the same as relativeStation(0, allRoute)
, which is described below.
Return this train's next platform info. (platInfo.plat.name to obtain the platform number)
Parameters:
allRoute
: Whether to also consider platforms outside the current running route.
This is the same as relativePlatform(0, allRoute)
, which is described below.
Return the platform at offset relative to the train's next station, or null if the specified platform is not in a station.
Parameters:
offset
: A number on how much to offset from the next station. (So0
for the next station,1
is the 2nd next station, and so on...)allRoute
: Whether to also consider stations outside the current running route.
Return the platform at offset relative to the train's next platform.
Parameters:
offset
: A number on how much to offset from the next platform. (So0
for the next station,1
is the 2nd next station, and so on...)allRoute
: Whether to also consider platforms outside the current running route.
Returns the station at the specified index, calculated from the start of the current route (Regardless of where the train is).
Parameters:
index
: The number of station counted from the start.allRoute
: If true, the "start" will be considered to be the first station on the first route the train runs.
Returns the platform at the specified index, calculated from the start of the current route (Regardless of where the train is).
Parameters:
index
: The number of station counted from the start.allRoute
: If true, the "start" will be considered to be the first station on the first route the train runs.
lastStation(allRoute: boolean): Station
Return this train's last station, returns a Station, or null if the last platform is not in a station.
Parameters:
allRoute
: Whether to also consider stations outside the current running route.
lastPlatform(allRoute: boolean): PlatformInfo
Return the PlatformInfo for the last platform of this train.
allRoute
means whether to also consider stations not on the current route.
Parameters:
allRoute
: Whether to also consider platforms outside the current running route.
nextPath(roundDown): PathData
Returns this train's next/current path, this is equivalant to relativePath(0)
.
Parameters:
roundDown
- Whether to obtain the section based on the train's head or the train's tail. By default this istrue
to match up with the behavior of thenextStation()
function, which is that the current path is returned.
relativePath(offset, roundDown): PathData
Returns the train's next/current path with an offset. null if the final index is out of bound.
Parameters:
roundDown
- Iftrue
(default), this will match up with the behavior of therelativeStation()
function, which is that the current path is returned if the train stopped exactly on a path.offset
: A number on how much to offset from the next path. (So0
for the next path,1
is the 2nd next path, and so on...)
Returns this train's destination name.
This could either be the train's last station name, or a name provided by custom destination.
Return whether the train is exactly stopped on a platform. (Note: This does not mean the door is opened)
This returns NaN
(Can check with isNaN()
function) if the train is not stopped at a platform.
Otherwise, it will return the remaining dwell time in seconds.
currentRoute(nullWhenTransitioning: boolean): Route
Return the current route the train is running.
Parameters:
nullWhenTransitioning
: If true, this will returnnull
when the train are running between route transition.
Return whether the next stop is the terminus of the current route.
Parameters:
allRoute
: If true, the terminus would be considered to be the last platform across all routes (aka the platform before the train returns to depot).
Whether the train is not supposed to be carrying passengers. This is true if the train is parked inside the depot, returning to the depot, has not reached the first platform yet, or has finished running the current route. (Might be en route to the next route)
Whether the train has finished running all it's route and are now returning to the depot.
Whether the door is opening (false
if door is fully opened, fully closed, or closing)
Whether the door is closing (false
if door is fully opened, fully closed, or opening)
Returns the train's speed in km/h
Returns the train's speed in mph
Returns the train's speed in Knot
// Include TrainHelper, make sure to replace the path with where you put your NTEUtil scripts!
include(Resources.id("mtr:custom_directory/nteutil/TrainHelper.js"));
function createTrain(ctx, state, train) {
// Create a new TrainHelper, this works per train
state.trainHelper = new TrainHelper(train);
}
function renderTrain(ctx, state, train) {
// Update our train data
state.trainHelper.tick(train);
if(state.trainHelper.doorOpeningOrOpened()) {
print("Train door is now open!");
}
if(state.trainHelper.terminating()) {
print("Train is now terminating, please leave!");
}
}