LuaTrain

class LuaTrain
get_item_count(item) → uint Get the amount of a particular item stored in the train.
get_contents() → dictionary stringuint Get a summary 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.
manual_mode :: boolean [RW] When true, the train is explicitly controlled by the player or script.
speed :: double [RW] Current speed.
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.
schedule :: TrainSchedule [RW]
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.
valid :: boolean [R] Is this object valid?

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 summary 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 :: SimpleItemStack: 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.

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.
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.

schedule :: TrainSchedule [Read-Write]

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.