LuaTrain

class LuaTrain - sort
get_item_count(item) → uint Get the amount of a particular item stored in the train.
get_contents() → dictionary stringuint Get a mapping of the train's inventory.
remove_item(stack) → uint Remove some items from the train.
insert(stack) Insert a stack into the train.
clear_items_inside() Clear all items in this train.
recalculate_path(force) → boolean Checks if the path is invalid and tries to re-path if it isn't.
get_fluid_count(fluid) → double Get the amount of a particular fluid stored in the train.
get_fluid_contents() → dictionary stringdouble Gets a mapping of the train's fluid inventory.
remove_fluid(fluid) → double Remove some fluid from the train.
insert_fluid(fluid) → double Inserts the given fluid into the first available location in this train.
clear_fluids_inside() Clears all fluids in this train.
go_to_station(index) Go to the station specified by the index in the train's schedule.
get_rails() → array of LuaEntity Gets all rails under the train.
manual_mode :: boolean [RW] When true, the train is explicitly controlled by the player or script.
speed :: double [RW] Current speed.
max_forward_speed :: double [R] Current max speed when moving forward, depends on locomotive prototype and fuel.
max_backward_speed :: double [R] Current max speed when moving backwards, depends on locomotive prototype and fuel.
weight :: double [R] The weight of this train.
carriages :: array of LuaEntity [R] Rolling stocks the train is composed of.
locomotives :: dictionary stringarray of LuaEntity [R] Arrays of locomotives.
cargo_wagons :: array of LuaEntity [R] The cargo carriages the train contains.
fluid_wagons :: array of LuaEntity [R] The fluid carriages the train contains.
schedule :: TrainSchedule [RW] The trains current schedule.
state :: defines.train_state [R] This train's current state.
front_rail :: LuaEntity [R] The rail at the front end of the train, possibly nil.
back_rail :: LuaEntity [R] The rail at the back end of the train, possibly nil.
rail_direction_from_front_rail :: defines.rail_direction [R]
rail_direction_from_back_rail :: defines.rail_direction [R]
front_stock :: LuaEntity [R] The front stock of this train or nil.
back_stock :: LuaEntity [R] The back stock of this train or nil.
station :: LuaEntity [R] The train stop this train is stopped at or nil.
has_path :: boolean [R] If this train has a path.
path_end_rail :: LuaEntity [R] The destination rail this train is currently pathing to or nil.
path_end_stop :: LuaEntity [R] The destination train stop this train is currently pathing to or nil.
id :: uint [R] The unique train ID.
passengers :: array of LuaPlayer [R] The player passengers on the train
riding_state :: RidingState [R] The riding state of this train.
killed_players :: dictionary uintuint [R] The players killed by this train.
kill_count :: uint [R] The total number of kills by this train.
path :: LuaRailPath [R] The path this train is using or nil if none.
signal :: LuaEntity [R] The signal this train is arriving or waiting at or nil if none.
valid :: boolean [R] Is this object valid?
help() → string All methods, and properties that this object supports.

A train. Trains are a sequence of connected rolling stocks -- locomotives and wagons.

get_item_count(item) → uint

Get the amount of a particular item stored in the train.

Parameters
item :: string (optional): Item name to count. If not given, counts all items.
get_contents() → dictionary stringuint

Get a mapping of the train's inventory.

Return value
The counts, indexed by item names.
remove_item(stack) → uint

Remove some items from the train.

Parameters
stack :: ItemStackSpecification: The amount and type of items to remove
Return value
Number of items actually removed.
insert(stack)

Insert a stack into the train.

Parameters
clear_items_inside()

Clear all items in this train.

recalculate_path(force) → boolean

Checks if the path is invalid and tries to re-path if it isn't.

Parameters
force :: boolean (optional): Forces the train to re-path regardless of the current path being valid or not.
Return value
If the train has a path after the repath attempt.
get_fluid_count(fluid) → double

Get the amount of a particular fluid stored in the train.

Parameters
fluid :: string (optional): Fluid name to count. If not given, counts all fluids.
get_fluid_contents() → dictionary stringdouble

Gets a mapping of the train's fluid inventory.

Return value
The counts, indexed by fluid names.
remove_fluid(fluid) → double

Remove some fluid from the train.

Parameters
fluid: A table with type and amount
Return value
The amount of fluid actually removed.
insert_fluid(fluid) → double

Inserts the given fluid into the first available location in this train.

Parameters
Return value
The amount inserted.
clear_fluids_inside()

Clears all fluids in this train.

go_to_station(index)

Go to the station specified by the index in the train's schedule.

Parameters
index :: uint
get_rails() → array of LuaEntity

Gets all rails under the train.

manual_mode :: boolean [Read-Write]

When true, the train is explicitly controlled by the player or script. When false, the train moves autonomously according to its schedule.

speed :: double [Read-Write]

Current speed.

Note: Changing the speed of the train is potentially an unsafe operation because train uses the speed for its internal calculations of break distances, etc.
max_forward_speed :: double [Read-only]

Current max speed when moving forward, depends on locomotive prototype and fuel.

max_backward_speed :: double [Read-only]

Current max speed when moving backwards, depends on locomotive prototype and fuel.

weight :: double [Read-only]

The weight of this train.

carriages :: array of LuaEntity [Read-only]

Rolling stocks the train is composed of.

locomotives :: dictionary stringarray of LuaEntity [Read-only]

Arrays of locomotives. The result is two arrays, indexed by "front_movers" and "back_movers" containing the locomotives. E.g. {front_movers={loco1, loco2}, back_movers={loco3}}.

cargo_wagons :: array of LuaEntity [Read-only]

The cargo carriages the train contains.

fluid_wagons :: array of LuaEntity [Read-only]

The fluid carriages the train contains.

schedule :: TrainSchedule [Read-Write]

The trains current schedule. Set to nil to clear.

Note: The schedule can't be changed by modifying the returned table. Instead, changes must be made by assigning a new table to this attribute.
state :: defines.train_state [Read-only]

This train's current state.

front_rail :: LuaEntity [Read-only]

The rail at the front end of the train, possibly nil.

back_rail :: LuaEntity [Read-only]

The rail at the back end of the train, possibly nil.

rail_direction_from_front_rail :: defines.rail_direction [Read-only]

rail_direction_from_back_rail :: defines.rail_direction [Read-only]

front_stock :: LuaEntity [Read-only]

The front stock of this train or nil.

back_stock :: LuaEntity [Read-only]

The back stock of this train or nil.

station :: LuaEntity [Read-only]

The train stop this train is stopped at or nil.

has_path :: boolean [Read-only]

If this train has a path.

path_end_rail :: LuaEntity [Read-only]

The destination rail this train is currently pathing to or nil.

path_end_stop :: LuaEntity [Read-only]

The destination train stop this train is currently pathing to or nil.

id :: uint [Read-only]

The unique train ID.

passengers :: array of LuaPlayer [Read-only]

The player passengers on the train

Note: This does *not* index using player index. See LuaPlayer::index on each player instance for the player index.
riding_state :: RidingState [Read-only]

The riding state of this train.

killed_players :: dictionary uintuint [Read-only]

The players killed by this train.

The keys are the player indexes, the values are how often this train killed that player.

kill_count :: uint [Read-only]

The total number of kills by this train.

path :: LuaRailPath [Read-only]

The path this train is using or nil if none.

signal :: LuaEntity [Read-only]

The signal this train is arriving or waiting at or nil if none.