A train. Trains are a sequence of connected rolling stocks -- locomotives and wagons.
booleanbooleanfalseWhen true, the train is explicitly controlled by the player or script. When false, the train moves autonomously according to its schedule.
doubledoublefalseCurrent speed.
Changing the speed of the train is potentially an unsafe operation because train uses the speed for its internal calculations of break distances, etc.
doubleunknownfalseCurrent max speed when moving forward, depends on locomotive prototype and fuel.
doubleunknownfalseCurrent max speed when moving backwards, depends on locomotive prototype and fuel.
doubleunknownfalseThe weight of this train.
Array<LuaEntity>unknownfalseThe rolling stocks this train is composed of, with the numbering starting at the front of the train.
{ back_movers: Array<LuaEntity>, front_movers: Array<LuaEntity> }unknownfalseLocomotives of the train.
Array<LuaEntity>unknownfalseThe cargo carriages the train contains.
Array<LuaEntity>unknownfalseThe fluid carriages the train contains.
TrainScheduleTrainScheduletrueThis train's current schedule, if any. Set to nil to clear.
The schedule can't be changed by modifying the returned table. Instead, changes must be made by assigning a new table to this attribute.
defines.train_stateunknownfalseThis train's current state.
LuaEntityunknowntrueThe front stock of this train, if any. The front of the train is in the direction that a majority of locomotives are pointing in. If it's a tie, the North and West directions take precedence.
LuaEntityunknowntrueThe back stock of this train, if any. The back of the train is at the opposite end of the front.
LuaEntityunknowntrueThe train stop this train is stopped at, if any.
booleanunknownfalseIf this train has a path.
LuaEntityunknowntrueThe destination rail this train is currently pathing to, if any.
LuaEntityunknowntrueThe destination train stop this train is currently pathing to, if any.
uint32unknownfalseThe unique train ID.
Array<LuaPlayer>unknownfalseThe player passengers on the train
This does *not* index using player index. See LuaPlayer::index on each player instance for the player index.
RidingStateunknownfalseThe riding state of this train.
Dict<uint32, uint32>unknownfalseThe players killed by this train.
The keys are the player indices, the values are how often this train killed that player.
uint32unknownfalseThe total number of kills by this train.
LuaRailPathunknowntrueThe path this train is using, if any.
LuaEntityunknowntrueThe signal this train is arriving or waiting at, if any.
stringstringfalseThe group this train belongs to.
Setting the group will apply the schedule of the group to this train.
LuaRailEndunknownfalseFront end of the train: Rail and direction on that rail where the train will go when moving forward
LuaRailEndunknownfalseBack end of the train: Rail and direction on that rail where the train will go when moving backward
booleanunknownfalseIs this object valid? This Lua object holds a reference to an object within the game engine. It is possible that the game-engine object is removed whilst a mod still holds the corresponding Lua object. If that happens, the object becomes invalid, i.e. this attribute will be false. Mods are advised to check for object validity if any change to the game state might have occurred between the creation of the Lua object and its access.
stringunknownfalseThe class name of this object. Available even when valid is false. For LuaStruct objects it may also be suffixed with a dotted path to a member of the struct.
LuaTrain.get_item_count(item?: ItemFilter) -> uint32
train.get_item_count()
takes_table: falsetable_optional: falseGet the amount of a particular item stored in the train.
item?: ItemFilter — If not given, counts all items.uint32LuaTrain.get_contents() -> ItemWithQualityCounts
train.get_contents()
takes_table: falsetable_optional: falseGet a mapping of the train's inventory.
ItemWithQualityCounts — List of all items in the train.LuaTrain.remove_item(stack: ItemStackIdentification) -> uint32
train.remove_item(stack)
takes_table: falsetable_optional: falseRemove some items from the train.
stack: ItemStackIdentification — The amount and type of items to removeuint32 — Number of items actually removed.LuaTrain.insert(stack: ItemStackIdentification)
train.insert(stack)
takes_table: falsetable_optional: falseInsert a stack into the train.
stack: ItemStackIdentificationLuaTrain.clear_items_inside()
train.clear_items_inside()
takes_table: falsetable_optional: falseClear all items in this train.
LuaTrain.recalculate_path(force?: boolean) -> boolean
train.recalculate_path()
takes_table: falsetable_optional: falseChecks if the path is invalid and tries to re-path if it isn't.
force?: boolean — Forces the train to re-path regardless of the current path being valid or not.boolean — If the train has a path after the repath attempt.LuaTrain.get_fluid_count(fluid?: string) -> double
train.get_fluid_count()
takes_table: falsetable_optional: falseGet the amount of a particular fluid stored in the train.
fluid?: string — Fluid name to count. If not given, counts all fluids.doubleLuaTrain.get_fluid_contents() -> Dict<string, FluidAmount>
train.get_fluid_contents()
takes_table: falsetable_optional: falseGets a mapping of the train's fluid inventory.
Dict<string, FluidAmount> — The counts, indexed by fluid names.LuaTrain.remove_fluid(fluid: Fluid) -> double
train.remove_fluid(fluid)
takes_table: falsetable_optional: falseRemove some fluid from the train.
fluid: Fluiddouble — The amount of fluid actually removed.LuaTrain.insert_fluid(fluid: Fluid) -> double
train.insert_fluid(fluid)
takes_table: falsetable_optional: falseInserts the given fluid into the first available location in this train.
fluid: Fluiddouble — The amount inserted.LuaTrain.clear_fluids_inside()
train.clear_fluids_inside()
takes_table: falsetable_optional: falseClears all fluids in this train.
LuaTrain.go_to_station(index: uint32)
train.go_to_station(index)
takes_table: falsetable_optional: falseGo to the station specified by the index in the train's schedule.
index: uint32LuaTrain.get_rails() -> Array<LuaEntity>
train.get_rails()
takes_table: falsetable_optional: falseGets all rails under the train.
Array<LuaEntity>LuaTrain.get_rail_end(direction: defines.rail_direction) -> LuaRailEnd
train.get_rail_end(direction)
takes_table: falsetable_optional: falseGets a LuaRailEnd object pointing away from the train at specified end of the train
direction: defines.rail_directionLuaRailEndLuaTrain.get_schedule() -> LuaSchedule
train.get_schedule()
takes_table: falsetable_optional: falseLuaSchedule