# FlyWithLua companion — FMS two-way sync X-Plane's Web API can't write a flight plan into the FMS. `fms-sync.lua` runs inside X-Plane (via FlyWithLua, which has the FMS SDK) and syncs the shared cockpit plan ↔ the in-sim FMS through two files in `Output/fms-sync/`. ## Install (sim PC only) 1. Install **FlyWithLua NG+** (free): copy its plugin folder into `/Resources/plugins/FlyWithLua/`. 2. Copy the scripts into `/Resources/plugins/FlyWithLua/Scripts/`: - **`fms-sync.lua`** — flight-plan two-way sync - **`ui-sync.lua`** — G1000 UI state (page / range / inset) - **`terrain-probe.lua`** — terrain-awareness elevation grid for the MFD 3. Restart X-Plane (or *FlyWithLua → Reload all Lua script files*). The log shows `[glass-cockpit] FMS sync active`. The bridge (desktop app / `node server/bridge.js`) must run on the **same PC** as X-Plane, so both see `/Output/fms-sync/`. ## What you get - **App → Sim:** load/build a plan in the web cockpit → it appears in the 3-D G1000 and the autopilot can fly it. - **Sim → App:** build/edit the plan in the real FMS → it shows on every tablet. - **Terrain:** the MFD TERRAIN map colours real scenery elevation red/yellow relative to your altitude (probed live by `terrain-probe.lua`). A 3-decimal lat/lon signature de-dupes the round-trip, so the two sides never loop. Waypoints are pushed as lat/lon legs (exact route; in-sim idents are generic — route accuracy over cosmetics).