Repository navigation
Station
Whether the train is at a platform, which one, and how long it has been there.
Four states, one at a time: running, stopping, stopped, departing.
stopped is the only one that means parked. It means the same thing the station block means when
it raises its flag, and it is kept across a save and reload.
The state is the same however the train got there, whether a driver, a schedule, a computer parking it, or the station building it.
True in stopping and stopped, so it covers braking into the platform as well as standing there.
Too broad to test for parked. Read getStationState() when you mean standing still.
One of "running", "stopping", "stopped", "departing".
local state = train.getStationState()
if state == "stopped" then
print("at the platform")
elseif state == "stopping" then
print("pulling in")
endat the platform
Name of the station the train is standing at or braking for. Nil when there is none.
The name stays after the stop ends. It is kept for about four blocks after the train pulls away, so a name on its own does not mean the train is still there. This is intentional, it keeps a car that rocks on its couplers from losing its station.
local name = train.getStationName()
if name and train.getStationState() == "stopped" then
print("parked at " .. name)
endparked at Central
Where the schedule is going next. Nil if no schedule is running.
Not the same as getStationName(), which is where the train is now. One is where it is going,
the other is the platform it is at.
print("dest: " .. (train.getTargetStationName() or "unknown"))How many ticks the train has been in the stopped state. It goes back to 0 as soon as it
leaves.
print("stopped for " .. math.floor(train.getDwellTicks() / 20) .. "s")stopped for 7s
Enforce a minimum stop time:
local MIN_DWELL = 100 -- five seconds
repeat os.sleep(0.5) until train.getDwellTicks() >= MIN_DWELLStart here
Reading the train
- Identity
- Motion
- State
- Station
- Signals
- Track ahead
- Orientation
- World position
- Carriages
- Consist wide cargo
Driving the train
Schedules
Doors and body
Links
The whole railway
Reacting to changes
Programs and reference
Start here
Controlling the plate
Automatic modes
Reading the turntable
Reference