Reference

Conditions

What a trigger waits for. Every object below needs "kind" plus its own fields. Source of truth: ScriptImport.makeCondition in CoachApp/ATC/ScriptImport.swift, resolving into a real TriggerCondition (CoachApp/Pilot/ArmedTrigger.swift).

Four condition kinds (reaches_fix, crosses_agl, agl_at_least, held, app_state) accept an optional not_before_trigger_id — a trigger id declared earlier. The condition is never even evaluated until that trigger has already fired. Use this whenever the same real-world event (the same fix, the same altitude, the same app state) could otherwise satisfy a LATER trigger's condition on its FIRST occurrence instead of the one it's actually meant for — e.g. a missed approach re-crossing the same AGL altitude the departure climb already did.

after_start timer

after_start

→ TriggerCondition.afterStart(seconds:)

fieldmeaning
secondsrequirednumber — fires this many seconds after the recording begins.
{ "kind": "after_start", "seconds": 2 }

after_gear_down timer

after_gear_down

→ TriggerCondition.afterGearDown(seconds:)

secondsrequirednumber — fires this many seconds after the gear extends (and stays down).
{ "kind": "after_gear_down", "seconds": 5 }

after_trigger chaining

after_trigger

→ TriggerCondition.afterTrigger(_:seconds:)

after_trigger_idrequireda trigger id declared earlier in this file.
secondsrequirednumber — fires this many seconds after that trigger fires. 0 is valid (same-tick chaining).
{ "kind": "after_trigger", "after_trigger_id": "t_welcome", "seconds": 3 }

after_any_trigger chaining

after_any_trigger

→ TriggerCondition.afterAnyTrigger(_:seconds:)

Fires this many seconds after whichever of several triggers fires first — the one real "OR" over trigger firings this format has. Use this to converge two branches a script can't otherwise merge back together (a yes/no choice, each with its own tail).

after_trigger_idsrequiredarray of trigger ids, non-empty.
secondsrequirednumber.
{ "kind": "after_any_trigger", "after_trigger_ids": ["t_yes_done", "t_no_done"], "seconds": 0 }

after_trigger_random_delay chaining

after_trigger_random_delay

→ TriggerCondition.afterTriggerRandomDelay(_:minSeconds:maxSeconds:)

Like after_trigger, but the delay is rolled once at random, live, the first time this trigger is actually checked after the referenced one has fired — not a fixed, script-authored wait. The rolled value is stable for this trigger's whole arm window (not re-rolled every sample).

after_trigger_idrequireda trigger id declared earlier.
min_secondsrequirednumber, <= max_seconds.
max_secondsrequirednumber.
{ "kind": "after_trigger_random_delay", "after_trigger_id": "t_arm", "min_seconds": 5, "max_seconds": 10 }

crosses_altitude telemetry edge

crosses_altitude

→ TriggerCondition.crossesAltitude(ft:climbing:)

feetrequirednumber — indicated altitude.
climbingrequiredbool — direction of crossing required.
{ "kind": "crosses_altitude", "feet": 4000, "climbing": true }

crosses_agl telemetry edge

crosses_agl

→ TriggerCondition.crossesAGL(ft:climbing:notBefore:)

feetrequirednumber — AGL altitude.
climbingrequiredbool.
not_before_trigger_idoptionaltrigger id — see the callout above.
{ "kind": "crosses_agl", "feet": 1000, "climbing": true, "not_before_trigger_id": "t_fail_3" }

agl_at_least level check

agl_at_least

→ TriggerCondition.aglAtLeast(ft:notBefore:)

True whenever the current AGL reading is already at or above the threshold — a level check, not an edge like crosses_agl's "must actually cross through it." Use this when a pilot could already be above the threshold before this trigger starts being evaluated at all (so there's no fresh crossing left to make).

feetrequirednumber.
not_before_trigger_idoptionaltrigger id.
{ "kind": "agl_at_least", "feet": 5, "not_before_trigger_id": "t_ptt_1" }

crosses_speed telemetry edge

crosses_speed

→ TriggerCondition.crossesSpeed(kts:accelerating:)

knotsone of knots / vspeed_refnumber — literal threshold.
vspeed_refone of knots / vspeed_refstring — see vspeed-relative thresholds.
vspeed_offset_ktsoptional, default 0number — added to the resolved vspeed.
acceleratingrequiredbool — direction of crossing.
{ "kind": "crosses_speed", "vspeed_ref": "vr", "vspeed_offset_kts": 1, "accelerating": true }

ias_at_most level check

ias_at_most

→ TriggerCondition.iasAtMost(_:)

True whenever indicated airspeed is already at or below the threshold — the steady-state sibling of agl_at_least (e.g. "taxied back and stopped" after a rejected takeoff).

knotsone of knots / vspeed_refnumber.
vspeed_refone of knots / vspeed_refstring.
vspeed_offset_ktsoptional, default 0number.
{ "kind": "ias_at_most", "knots": 5 }

rpm_at_least_all_engines engine telemetry

rpm_at_least_all_engines

→ TriggerCondition.rpmAtLeastAllEngines(_:)

True iff every active engine's RPM is at or above the threshold. Deliberately folds in "how many engines does this airframe have right now" (single vs. multi) — "all active engines" already means whichever count the connected airframe reports, so no separate engine-mode condition exists.

rpm_at_leastrequirednumber.
{ "kind": "rpm_at_least_all_engines", "rpm_at_least": 500 }

bank_at_least level check

bank_at_least

→ TriggerCondition.bankAtLeast(_:)

True whenever the current bank angle's MAGNITUDE is at or above the threshold, either direction — a level check, not an edge, same shape as ias_at_most/agl_at_least. Deliberately direction-agnostic: a script already knows which way it told the pilot to roll (it's the one dictating "turn left" vs. "turn right"), so this only has to confirm bank was actually established, for a steep turn, an unusual-attitude recovery, or any other maneuver graded on sustained bank. Pair with all_of + after_trigger(..., seconds: 0) against a PTT/ briefing trigger to stop it from catching a stray bank angle before the pilot was actually told to turn.

degreesrequirednumber.
{ "kind": "all_of", "conditions": [
  { "kind": "bank_at_least", "degrees": 45 },
  { "kind": "after_trigger", "after_trigger_id": "t_ptt_confirm", "seconds": 0 }
] }

near_runway_end geo

near_runway_end

→ TriggerCondition.nearRunwayEnd(withinFt:alignedToleranceDeg:)

True while within within_ft of a real charted runway end (resolved live against the bundled CIFP database) AND the aircraft's heading is within aligned_tolerance_deg of EITHER that end's published heading or its reciprocal — a runway's two idents are ~180° apart, so "pointed down the runway" correctly accepts either direction of the one strip.

within_ftrequirednumber.
aligned_tolerance_degrequirednumber.
{ "kind": "near_runway_end", "within_ft": 500, "aligned_tolerance_deg": 20 }

Common composite, "ready for takeoff": all_of of ias_at_most + rpm_at_least_all_engines + near_runway_end — see all_of and the worked example.

reaches_fix position

reaches_fix

→ TriggerCondition.reachesFix(_:withinNm:notBefore:)

fixrequiredstring — a real charted fix/navaid ident.
within_nmoptional, default 1.0number.
not_before_trigger_idoptionaltrigger id.
{ "kind": "reaches_fix", "fix": "YUBBA", "within_nm": 2 }

reaches_fix_with_turn_lead position

reaches_fix_with_turn_lead

→ TriggerCondition.reachesFixWithTurnLead(_:outboundCourseDeg:notBefore:)

Like reaches_fix, but for a real fly-by fix: the capture radius isn't a fixed NM value picked at authoring time, it's the actual lead distance a standard-rate turn needs, computed live from the aircraft's own current groundspeed and the real course change at the fix (current track → outbound_course_deg).

fixrequiredstring.
outbound_course_degrequirednumber.
not_before_trigger_idoptionaltrigger id.
{ "kind": "reaches_fix_with_turn_lead", "fix": "YUBBA", "outbound_course_deg": 74 }

reaches_fix_for_entry_type position, hold entry

reaches_fix_for_entry_type

→ TriggerCondition.reachesFixForEntryType(_:withinNm:type:classifiedAt:)

Fires once within within_nm of fix, but only for the one hold entry type (teardrop/parallel/direct) actually classified at classified_at_trigger_id's own fire — the gate for one specific entry type's own discrete step-by-step walkthrough. All three entry types' own first discrete step watch the same fix, so each needs its own type check to avoid narrating the wrong procedure.

fixrequiredstring.
within_nmoptional, default 1.0number.
entry_typerequiredone of teardrop / parallel / direct.
classified_at_trigger_idrequiredtrigger id — whichever trigger's own fire classified the entry type (typically a swift_classifier-graded hold-entry moment, or an app_state/ui_action trigger a script sets up for this purpose).
{ "kind": "reaches_fix_for_entry_type", "fix": "SAC", "within_nm": 2,
  "entry_type": "teardrop", "classified_at_trigger_id": "t_entry_classified" }

after_trigger_or_reaches_fix chaining + position

after_trigger_or_reaches_fix

→ TriggerCondition.afterTriggerOrReachesFix(_:seconds:fixIdent:withinNm:)

Fires at whichever comes first: seconds after the named trigger fired, or within within_nm of fix. Models a controller issuing an assignment proactively on a timer, rather than waiting indefinitely for a tracking-quality condition the pilot might take a long time to satisfy.

after_trigger_idrequiredtrigger id.
secondsrequirednumber.
fixrequiredstring.
within_nmoptional, default 1.0number.
{ "kind": "after_trigger_or_reaches_fix", "after_trigger_id": "t_hold_assigned", "seconds": 300,
  "fix": "SAC", "within_nm": 10 }

reaches_point position

reaches_point

→ TriggerCondition.reachesPoint(lat:lon:withinNm:notBefore:)

Like reaches_fix, but for a raw lat/lon instead of a named, database-resolvable fix — a real ATC vectoring waypoint that isn't actually a charted fix at all.

latrequirednumber.
lonrequirednumber.
within_nmoptional, default 1.0number.
not_before_trigger_idoptionaltrigger id.
{ "kind": "reaches_point", "lat": 36.98, "lon": -121.68, "within_nm": 2 }

obs_rotated radio/instrument

obs_rotated

→ TriggerCondition.obsRotated(sinceTrigger:degrees:)

The OBS has moved at least degrees from whatever it read the instant since_trigger_id fired — a one-shot "did the pilot actually touch the knob" check, not a sustained held condition.

since_trigger_idrequiredtrigger id.
degreesrequirednumber.
{ "kind": "obs_rotated", "since_trigger_id": "t_ask_to_rotate", "degrees": 30 }

ptt_pressed radio

ptt_pressed

→ TriggerCondition.pttPressed(notBefore:)

Fires the instant a PTT-bound radio control flips false→true — a real transmission beginning, not motion/position/course. Only a Companion-fed flight can ever report this (TriggerSample.pttOn is nil off a device recording or the virtual pilot) — but the app's own on-screen PTT-fallback button can advance past this wait on any flight, so author it freely.

not_before_trigger_idoptionaltrigger id.
{ "kind": "ptt_pressed" }

ptt_released radio

ptt_released

→ TriggerCondition.pttReleased(notBefore:)

The mirror of ptt_pressed — fires on true→false. Used for clearance/readback pacing (the app can't parse speech, only timing): name the clearance trigger's own id as a later readback trigger's not_before_trigger_id, so the pilot's first keyup can't also satisfy the readback.

not_before_trigger_idoptionaltrigger id.
{ "kind": "ptt_released", "not_before_trigger_id": "t_clearance" }

held latched

held

→ TriggerCondition.held(_:forSeconds:notBefore:)

Fires once the named sub-condition (held_kind) has stayed continuously true for for_seconds. Twelve held_kind values import today — don't invent one the importer doesn't support, it will be silently dropped with a warning.

for_secondsrequirednumber.
held_kindrequiredstring — see below.
not_before_trigger_idoptionaltrigger id.

held_kind: established_on_course

course_degrequirednumber.
within_dotsrequirednumber — visible CDI dot count.
heading_within_degrequirednumber.

Needle within tolerance AND heading within tolerance of the course — what "established" actually means, not a centered needle alone.

{ "kind": "held", "for_seconds": 10,
  "held_kind": "established_on_course", "course_deg": 251, "within_dots": 1.0, "heading_within_deg": 15 }

held_kind: needle_centered

within_dotsrequirednumber — visible CDI dot count.

The needle alone, with no heading check — prefer established_on_course for a real "established on course" beat; this is for a narrower "needle happens to read centered" check.

{ "kind": "held", "for_seconds": 5, "held_kind": "needle_centered", "within_dots": 0.5 }

held_kind: established

within_dotsrequirednumber.
heading_within_degrequirednumber.

Like established_on_course, but without a fixed course_deg of its own — needle within tolerance AND heading within tolerance of whatever course happens to be dialed.

{ "kind": "held", "for_seconds": 10, "held_kind": "established", "within_dots": 1.0, "heading_within_deg": 15 }

held_kind: off_course

min_dotsrequirednumber — visible CDI dot count.
{ "kind": "held", "for_seconds": 3, "held_kind": "off_course", "min_dots": 1.0 }

held_kind: glideslope_captured

within_dotsrequirednumber — visible dot count, vertical needle.
{ "kind": "held", "for_seconds": 5, "held_kind": "glideslope_captured", "within_dots": 0.5 }

held_kind: reverse_sensing

No fields. True once the aircraft's heading is more than 90° off the OBS-selected course — the standard reverse-sensing rule.

{ "kind": "held", "for_seconds": 3, "held_kind": "reverse_sensing" }

held_kind: heading_within

target_degrequirednumber.
within_degrequirednumber.
{ "kind": "held", "for_seconds": 5, "held_kind": "heading_within", "target_deg": 74, "within_deg": 10 }

held_kind: obs_stable

within_degrequirednumber.

True while the OBS hasn't moved by more than within_deg since the previous sample — "the knob isn't actively being turned right now," not "near some fixed value."

{ "kind": "held", "for_seconds": 2, "held_kind": "obs_stable", "within_deg": 2 }

held_kind: heading_stable

within_degrequirednumber.

The heading analogue of obs_stable — "the turn is done, now holding a steady heading," without checking which heading it actually is.

{ "kind": "held", "for_seconds": 2, "held_kind": "heading_stable", "within_deg": 3 }

held_kind: arc_distance_too_far / arc_distance_too_close

stationrequiredstring — a real navaid ident.
target_nmrequirednumber.
tolerance_nmrequirednumber.

True while more than tolerance_nm beyond (too_far) or inside (too_close) target_nm from station — "drifted outside a DME arc," firing a correction turn.

{ "kind": "held", "for_seconds": 2, "held_kind": "arc_distance_too_far",
  "station": "RBL", "target_nm": 19, "tolerance_nm": 1 }

held_kind: level_flight

pitch_tolerance_degrequirednumber.
bank_tolerance_degrequirednumber.
vsi_tolerance_fpmrequirednumber.
{ "kind": "held", "for_seconds": 3, "held_kind": "level_flight",
  "pitch_tolerance_deg": 10, "bank_tolerance_deg": 10, "vsi_tolerance_fpm": 300 }

counter_at_least retry/loop

counter_at_least

→ TriggerCondition.counterAtLeast(key:count:)

True once a named counter reads at or above count — the generic "give up after N attempts" primitive. Pair with increment_counter.

counter_idrequiredstring — a plain, script-authored counter key.
countrequiredinteger.
{ "kind": "counter_at_least", "counter_id": "s3_crash_count", "count": 2 }

all_of combinator

all_of

→ TriggerCondition.allOf([_])

True iff every one of conditions is true on the same sample — the one true AND this format has. (after_trigger only measures time since something FIRED, not "are these steady-state checks all true right now.") Composite waits like "ready for takeoff" are built this way, not as a monolithic condition kind.

conditionsrequiredarray of Condition, non-empty. Each one may itself be any kind, including nested all_of/not.
{ "kind": "all_of", "conditions": [
  { "kind": "ias_at_most", "knots": 5 },
  { "kind": "rpm_at_least_all_engines", "rpm_at_least": 500 },
  { "kind": "near_runway_end", "within_ft": 500, "aligned_tolerance_deg": 20 }
] }

not combinator

not

→ TriggerCondition.not(_:)

True iff the nested condition is false — the logical complement all_of needs to express "AND NOT," e.g. a retry beat gated on "the give-up counter has NOT yet reached threshold."

conditionrequiredone nested Condition object (wire key is "condition", singular — not conditions).
{ "kind": "not", "condition": { "kind": "counter_at_least", "counter_id": "s3_crash_count", "count": 2 } }

app_state app state

app_state

→ TriggerCondition.appState(_:notBefore:)

True the instant a named, non-telemetry check (registered in App.swift's appStateChecks) reads true — "the pilot is signed in," "this engine mode is multi," "this Failures scenario is armed." Keys are app-specific and grow as new checks are registered; ask a Coach engineer before relying on one not already documented in a worked example.

state_keyrequiredstring.
not_before_trigger_idoptionaltrigger id — important here, since an app-state check with no gate is live from the mission's very first sample.
{ "kind": "app_state", "state_key": "engine_mode_multi" }

ui_action app state

ui_action

→ TriggerCondition.uiAction(_:)

Fired directly by a specific pilot UI action (adding a hold, toggling a preset, tapping a cue-card button via fires_ui_action — see choice) — never evaluated against telemetry, since there's no sample-based signal for "the pilot tapped this."

action_idrequiredstring — matched against whatever fired it.
{ "kind": "ui_action", "action_id": "hold_added" }

Coverage

Every real TriggerCondition and HoldCondition case has a JSON import form today (as of 2026-11-22 — reaches_fix_with_turn_lead, reaches_fix_for_entry_type, after_trigger_or_reaches_fix, obs_rotated, reaches_point, and the remaining nine held_kind values all closed the previous gap here, since a hand-authored Swift lesson could use them but a JSON-authored one couldn't). If a future Swift change adds a new condition case with no matching case "...": arm in ScriptImport.makeCondition/ makeHoldCondition yet, it belongs back in a section like this one — see Maintaining this spec → Verifying accuracy for how to check.