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.
valid :: boolean [R] Is this object valid?
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.trainstate [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]

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.

valid :: boolean [Read-only]

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

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.trainstate [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]