Train

Train

class

Train on the railway of a surface. Schedule edits go out to the other peers the way the train window sends them and land at the host's stamped tick

  • read-only Assigning to the field raises an error.

Fields

NameTypeDescription
id read-only integer Number of the train, the same on every peer and across saves
name read-only string? Name the player gave the train, nil while it has none
cars read-only StaticItem[] Car items from the front of the train to its back
stops read-only TrainScheduleStop[] Stops of the schedule in order
current_stop read-only TrainScheduleStop? Stop the train goes to or stands at, nil while the schedule is empty
loop read-only boolean Whether the schedule starts over after its last stop

Functions

Train:set_name(name)

Name the train the way its window does

name string New name, empty to take the name away

returns boolean True when the edit was taken; false when the train has that name already

Train:add_stop(station, before)

Add a stop to the schedule

station string Station name
before TrainScheduleStop? Stop the new one goes before, nil to add it at the end

returns boolean True when the edit was taken

Train:remove_stop(stop)

Take a stop out of the schedule

stop TrainScheduleStop Stop of this train

returns boolean True when the edit was taken

Train:move_stop(stop, before)

Move a stop within the schedule

stop TrainScheduleStop Stop of this train
before TrainScheduleStop? Stop it goes before, nil to move it to the end

returns boolean True when the edit was taken; false when the stop is there already

Train:set_stop_station(stop, station)

Send a stop to another station

stop TrainScheduleStop Stop of this train
station string Station name

returns boolean True when the edit was taken; false when the stop goes there already

Train:set_condition(stop, condition)

Replace when the train leaves a stop

stop TrainScheduleStop Stop of this train
condition table Whole condition, in the shape TrainScheduleStop.condition reads

returns boolean True when the edit was taken

Train:set_loop(loop)

Make the schedule start over after its last stop or end there

loop boolean Start over

returns boolean True when the edit was taken; false when the schedule is that way already

Train:set_current_stop(stop)

Send the train to a stop of its schedule

stop TrainScheduleStop Stop of this train

returns boolean True when the edit was taken; false when it goes there already

Train:depart()

Make the train waiting at its stop leave without its condition

returns boolean True when the edit was taken; false when the train is not waiting at a stop or has nowhere to go

Standard members (4)

Every class of this kind carries these.

Train.cast(object) Trying to cast Object into Train
Train.get_class() Return Train class object
Train.new(parent, name) Creates a new Train instance
Train.new_simple() Creates a new Train instance
Inherited from Instance (1)
Inherited from Object (2)

Used by