Skip to content

Train

$object.train:description$

Properties

active

$object.train.active:description$

blocks

$object.train.blocks:description$

emergency_stop

true if emergency stop is active, false otherwise.

has_throttle

$object.train.has_throttle:description$

id

Unique object identifier. Each object in Traintastic has a globally unique id that can be used in scripts (see world.get_object).

is_stopped

true if the train's velocity is zero, false if the train's velocity is greater than zero.

mode

$object.train.mode:description$

mute

If true, mutes all trains in the zone.

name

Train name

no_smoke

If true, disables smoke generators of all trains in the zone.s

powered

true if the train contains a rail vehicle that can power the train, false otherwise.

throttle_name

$object.train.throttle_name:description$

zones

List of train zone status objects of all zones that the train is entering, has entered and/or is leaving.

Methods

stop()

Stop the train, sets the speed to zero.

Events

on_block_assigned

Fired when the train is assigned to a block.

Handler signature

function (train, block, user_data)

Arguments

  • train - The train.

  • block - The block the train is assigned to.

  • user_data - optional user-provided value (see Events).

on_block_entered

Fired when the train enters a block.

Handler signature

function (train, block, direction, user_data)

Arguments

  • train - The train.

  • block - The block that is entered.

  • direction - Train direction from the block perspective, a Block train direction value.

  • user_data - optional user-provided value (see Events).

on_block_left

Fired when the train has left a block.

Handler signature

function (train, block, direction, user_data)

Arguments

  • train - The train.

  • block - The block that the train left.

  • direction - Train direction from the block perspective, a Block train direction value.

  • user_data - optional user-provided value (see Events).

on_block_removed

Fired when the train is removed from a block.

Handler signature

function (train, block, user_data)

Arguments

  • train - The train.

  • block - The block the train is removed from.

  • user_data - optional user-provided value (see Events).

on_block_reserved

Fired when the train reserves a block.

Handler signature

function (train, block, direction, user_data)

Arguments

  • train - The train.

  • block - The block that is reserved by the train.

  • direction - Train direction from the block perspective, a Block train direction value.

  • user_data - optional user-provided value (see Events).

on_zone_assigned

Fired when the train is assigned to the first block of a zone.

Handler signature

function (train, zone, user_data)

Arguments

  • train - The train.

  • zone - The zone that the train is assigned to.

  • user_data - optional user-provided value (see Events).

on_zone_entered

Fired when the train is in a zone, the train is in a zone when it only occupies blocks that are part of a zone.

Handler signature

function (train, zone, user_data)

Arguments

  • train - The train.

  • zone - The zone that the train has entered.

  • user_data - optional user-provided value (see Events).

on_zone_entering

Fired when the train reserves or enters the first block of a zone it currently isn't in.

Handler signature

function (train, zone, user_data)

Arguments

  • train - The train.

  • zone - The zone that the train is entering.

  • user_data - optional user-provided value (see Events).

on_zone_leaving

Fired when the train reserves or enters a block that is not part of a zone it currently is in.

Handler signature

function (train, zone, user_data)

Arguments

  • train - The train.

  • zone - The zone that the train is leaving.

  • user_data - optional user-provided value (see Events).

on_zone_left

Fired when the train is no longer in a zone, the train is not longer in a zone when it doesn't occupy any block that is part of a zone.

Handler signature

function (train, zone, user_data)

Arguments

  • train - The train.

  • zone - The zone that the train left.

  • user_data - optional user-provided value (see Events).

on_zone_removed

Fired when the train is removed from the last block of a zone.

Handler signature

function (train, zone, user_data)

Arguments

  • train - The train.

  • zone - The zone that the train is removed from.

  • user_data - optional user-provided value (see Events).