Repository navigation
State
Five true or false values and one number, all read only, none needing a control lease. Use these in monitoring loops.
True while every bogey is on track.
The opposite of isRailed(). Both exist so you can write the test either way round, use whichever
reads better.
A derailed train ignores almost everything. Body offsets, target speed and steering stop having any effect until it is back on the rails, because a derailed car follows its physics body and not the rail.
Use events instead of polling. train_derailed and train_rerailed fire when it changes,
which is cheaper than checking every tick.
if train.isDerailed() then
print("derailed")
redstone.setOutput("top", true)
endDerail events do not fire when the world loads. A train that was already off the rails when the world saved comes back derailed with no event, so read this once at startup before you start waiting for events.
True if any brake is on. That includes the short automatic brake at the end of a station stop, so it turns true on arrival even when nobody pulled a brake.
True only for the handbrake, the one a player pulls. The automatic station brake does not set it.
Use this to detect a player taking over. A program that keeps driving while the handbrake is pulled overrides the player in the cab.
if train.isBrakeHard() then
print("handbrake pulled, handing back")
train.setTargetSpeed(0)
train.release()
return
endTrue while the schedule is holding the train, waiting for a departure condition, a red signal or a route.
Read getHeldReason() to find out why, though it only names hardware faults.
Current steering input. -1 left, 0 straight, 1 right.
It reports the computer's value while one is set. If a computer called steer(), this reads that
value back. Otherwise it reports what the axle sees from its redstone links.
local dir = train.getSteerInput()
print(dir == -1 and "left" or dir == 1 and "right" or "straight")left
Start 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