en
Sign in

← Back to the API reference

DutyStep A duty's stop

What a method is given when a duty's stop calls it. In the duty editor you choose per stop (at the expert level) a moment -- the agent sets off for the stop, arrives, leaves it again, or waits for its way there (every five seconds) -- and a method from your scripts that takes a DutyStep, or nothing. Such a method can be in a script, static in a class, or on an object Main shares.

What for: To do something at a fixed point of a duty without looking up events: announce at stop 2, a light on while the train waits for its way, a count per run.

// in Main
chef = new StationMaster()

class StationMaster {
   void arrival(DutyStep s) {
      Trax.layout.announce "The ${s.train.name} is arriving"
   }
}
// in the duty editor, at stop 2: arrives → chef.arrival()

Properties

train → Train

The train whose agent goes through the stop.

The train's object, as in trains.

void atStop(DutyStep s) { log s.train.name }

step → int

Which stop of the duty, counted from 1.

The number as the duty editor shows it. On a shuttle the same stop comes again on the way back.

void atStop(DutyStep s) { if (s.step == 2) say "stop 2" }

moment → String

start, arrived, finished or waiting.

start: the agent sets off for the stop. arrived: it is there. finished: it leaves again, the stop is done. waiting: it waits for its way there, every five seconds. Useful when one method is chosen for several moments.

void atStop(DutyStep s) {
   if (s.moment == "waiting") log "waiting ${s.seconds} s"
}

place → Place

The stop's station or yard; null when the stop is one block.

A stop goes to a place (any free track there) or to one block; for a place, it is here.

void atStop(DutyStep s) { log s.place?.name }

block → Block

The stop's block, when it is one.

null when the stop is a station or yard.

void atStop(DutyStep s) { log s.block?.name }

seconds → int

While waiting: how long, in seconds.

Only for waiting; otherwise 0.

void waits(DutyStep s) { if (s.seconds >= 60) say "a long wait" }

reason → String

While waiting: why, in TRAX Control's words.

Only for waiting; otherwise empty.

void waits(DutyStep s) { log s.reason }