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
→ TriggerCondition.afterStart(seconds:)
| field | meaning | |
|---|---|---|
| seconds | required | number — fires this many seconds after the recording begins. |
{ "kind": "after_start", "seconds": 2 }
after_gear_down timer
→ TriggerCondition.afterGearDown(seconds:)
| seconds | required | number — fires this many seconds after the gear extends (and stays down). |
{ "kind": "after_gear_down", "seconds": 5 }
after_trigger chaining
→ TriggerCondition.afterTrigger(_:seconds:)
| after_trigger_id | required | a trigger id declared earlier in this file. |
| seconds | required | number — 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
→ 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_ids | required | array of trigger ids, non-empty. |
| seconds | required | number. |
{ "kind": "after_any_trigger", "after_trigger_ids": ["t_yes_done", "t_no_done"], "seconds": 0 }
after_trigger_random_delay chaining
→ 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_id | required | a trigger id declared earlier. |
| min_seconds | required | number, <= max_seconds. |
| max_seconds | required | number. |
{ "kind": "after_trigger_random_delay", "after_trigger_id": "t_arm", "min_seconds": 5, "max_seconds": 10 }
crosses_altitude telemetry edge
→ TriggerCondition.crossesAltitude(ft:climbing:)
| feet | required | number — indicated altitude. |
| climbing | required | bool — direction of crossing required. |
{ "kind": "crosses_altitude", "feet": 4000, "climbing": true }
crosses_agl telemetry edge
→ TriggerCondition.crossesAGL(ft:climbing:notBefore:)
| feet | required | number — AGL altitude. |
| climbing | required | bool. |
| not_before_trigger_id | optional | trigger id — see the callout above. |
{ "kind": "crosses_agl", "feet": 1000, "climbing": true, "not_before_trigger_id": "t_fail_3" }
agl_at_least level check
→ 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).
| feet | required | number. |
| not_before_trigger_id | optional | trigger id. |
{ "kind": "agl_at_least", "feet": 5, "not_before_trigger_id": "t_ptt_1" }
crosses_speed telemetry edge
→ TriggerCondition.crossesSpeed(kts:accelerating:)
| knots | one of knots / vspeed_ref | number — literal threshold. |
| vspeed_ref | one of knots / vspeed_ref | string — see vspeed-relative thresholds. |
| vspeed_offset_kts | optional, default 0 | number — added to the resolved vspeed. |
| accelerating | required | bool — direction of crossing. |
{ "kind": "crosses_speed", "vspeed_ref": "vr", "vspeed_offset_kts": 1, "accelerating": true }
ias_at_most level check
→ 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).
| knots | one of knots / vspeed_ref | number. |
| vspeed_ref | one of knots / vspeed_ref | string. |
| vspeed_offset_kts | optional, default 0 | number. |
{ "kind": "ias_at_most", "knots": 5 }
rpm_at_least_all_engines engine telemetry
→ 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_least | required | number. |
{ "kind": "rpm_at_least_all_engines", "rpm_at_least": 500 }
bank_at_least level check
→ 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.
| degrees | required | number. |
{ "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
→ 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_ft | required | number. |
| aligned_tolerance_deg | required | number. |
{ "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
→ TriggerCondition.reachesFix(_:withinNm:notBefore:)
| fix | required | string — a real charted fix/navaid ident. |
| within_nm | optional, default 1.0 | number. |
| not_before_trigger_id | optional | trigger id. |
{ "kind": "reaches_fix", "fix": "YUBBA", "within_nm": 2 }
reaches_fix_with_turn_lead position
→ 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).
| fix | required | string. |
| outbound_course_deg | required | number. |
| not_before_trigger_id | optional | trigger id. |
{ "kind": "reaches_fix_with_turn_lead", "fix": "YUBBA", "outbound_course_deg": 74 }
reaches_fix_for_entry_type position, hold entry
→ 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.
| fix | required | string. |
| within_nm | optional, default 1.0 | number. |
| entry_type | required | one of teardrop / parallel / direct. |
| classified_at_trigger_id | required | trigger 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
→ 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_id | required | trigger id. |
| seconds | required | number. |
| fix | required | string. |
| within_nm | optional, default 1.0 | number. |
{ "kind": "after_trigger_or_reaches_fix", "after_trigger_id": "t_hold_assigned", "seconds": 300,
"fix": "SAC", "within_nm": 10 }
reaches_point position
→ 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.
| lat | required | number. |
| lon | required | number. |
| within_nm | optional, default 1.0 | number. |
| not_before_trigger_id | optional | trigger id. |
{ "kind": "reaches_point", "lat": 36.98, "lon": -121.68, "within_nm": 2 }
obs_rotated radio/instrument
→ 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_id | required | trigger id. |
| degrees | required | number. |
{ "kind": "obs_rotated", "since_trigger_id": "t_ask_to_rotate", "degrees": 30 }
ptt_pressed radio
→ 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_id | optional | trigger id. |
{ "kind": "ptt_pressed" }
ptt_released radio
→ 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_id | optional | trigger id. |
{ "kind": "ptt_released", "not_before_trigger_id": "t_clearance" }
held latched
→ 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_seconds | required | number. |
| held_kind | required | string — see below. |
| not_before_trigger_id | optional | trigger id. |
held_kind: established_on_course
| course_deg | required | number. |
| within_dots | required | number — visible CDI dot count. |
| heading_within_deg | required | number. |
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_dots | required | number — 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_dots | required | number. |
| heading_within_deg | required | number. |
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_dots | required | number — visible CDI dot count. |
{ "kind": "held", "for_seconds": 3, "held_kind": "off_course", "min_dots": 1.0 }
held_kind: glideslope_captured
| within_dots | required | number — 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_deg | required | number. |
| within_deg | required | number. |
{ "kind": "held", "for_seconds": 5, "held_kind": "heading_within", "target_deg": 74, "within_deg": 10 }
held_kind: obs_stable
| within_deg | required | number. |
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_deg | required | number. |
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
| station | required | string — a real navaid ident. |
| target_nm | required | number. |
| tolerance_nm | required | number. |
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_deg | required | number. |
| bank_tolerance_deg | required | number. |
| vsi_tolerance_fpm | required | number. |
{ "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
→ 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_id | required | string — a plain, script-authored counter key. |
| count | required | integer. |
{ "kind": "counter_at_least", "counter_id": "s3_crash_count", "count": 2 }
all_of combinator
→ 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.
| conditions | required | array 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
→ 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."
| condition | required | one 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
→ 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_key | required | string. |
| not_before_trigger_id | optional | trigger 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
→ 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_id | required | string — 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.