de
Anmelden

← Zurück zur API-Referenz

Train A train

A train made up on your layout, as in the Trains panel. It knows where it is, and tells when it enters or leaves a station or block, when its agent waits or chooses a track, and when it runs late.

Wofür: To react to one particular train (an announcement for the IC), to let its agent run a duty or stop it, and to send it to another track.

trains.IC.onArrival { Place station ->
   announce "The IC is arriving at ${station.name}"
}
trains.IC.startAgent(duties.Shuttle)

Properties

name → String

Its name.

The train's name as in the Trains panel. Changes when you rename it; the object stays the same.

trains.IC.onArrival { Place p -> log "${trains.IC.name} at ${p.name}" }

Methoden

arriveAt

The track its agent is to take at the stop it goes to now; tried at once when it waits.

Tells the agent which track to arrive on at the stop it is heading for now; for that stop only. If the agent is waiting, it tries at once. TRAX Control chooses the route there, through the interlocking.

trains.IC.onWaiting { Waiting w ->
   if (w.place && w.seconds >= 60) {
      Block free = w.place.freeTracks.find()
      if (free) trains.IC.arriveAt(free)
   }
}

isIn → boolean

Whether it stands in a block or a place now.

Whether the train stands in this block or place now, as TRAX Control follows it. A live query.

if (trains.IC.isIn(stations.South)) {
   log "the IC is in South"
}

startAgent

Starts its agent, on its own duty or the one given.

Starts the train's agent: without an argument on the duty the train already has, or on the duty given. Refused (exception) when your edition allows no more agents, or the train is not on the layout.

try {
   trains.IC.startAgent(duties.Shuttle)
} catch (Exception e) {
   log "not started: ${e.message}"
}

stopAgent

Stops its agent where it is.

Stops the agent: the train brakes to a stand and is no longer driven by itself.

clock.at("23:00") {
   trains.IC.stopAgent()
}

Events

onArrival → Place

When it comes into a station or yard.

Fires when the train comes into a station, shunting yard, staging yard or depot. Gives the Place. For every train at once use place.onArrival.

trains.IC.onArrival { Place place ->
   announce "The IC is arriving at ${place.name}"
}

onDeparture → Place

When it has left a station or yard altogether.

Fires when the train has left a place altogether: its tail is out too.

trains.IC.onDeparture { Place place ->
   log "IC left ${place.name}"
}

onEntered → Block

When its front comes into a block.

Fires when the train's front enters a block, as TRAX Control follows the train. Gives the Block.

trains.IC.onEntered { Block block ->
   if (block == blocks.B7) log "IC on the level crossing"
}

onLeft → Block

When it has left a block altogether.

Fires when the train has left a block altogether.

trains.IC.onLeft { Block block ->
   log "IC out of ${block.name}"
}

onWaiting → Waiting

When its agent waits for its way to its next stop: at once and every half minute.

Fires when this train's agent waits for its route to the next stop: at once, then every half minute while it waits. Gives a Waiting with how long and why.

trains.IC.onWaiting { Waiting w ->
   if (w.seconds >= 120) say "The IC has waited two minutes: ${w.reason}"
}

onTrackChosen → Block

When its agent chose its track in a station or yard.

Fires when this train's agent has chosen a track in a station or yard. Gives the Block.

trains.IC.onTrackChosen { Block track ->
   announce "The IC arrives on track ${track.name}"
}

onDelayed → Delay

When it runs late on its timetable's service: at the threshold, and again at every as many more.

Fires when the train runs late on its timetable service: at the threshold from the settings, then each time that many minutes more. Gives a Delay.

trains.IC.onDelayed { Delay d ->
   announce "Service ${d.service} is ${d.minutes} minutes late"
}

onNotThere → NotThere

When it is not where its circulation expects it: not at the first stop of its run when due, or not ready to join another train.

Fires when the train is not where its circulation expects it: not at the first stop when its run is due, or not ready to join another train. Gives a NotThere.

trains.IC.onNotThere { NotThere n ->
   say "IC is not ready for service ${n.service}"
}