# 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. Start the bridge (desktop app or `node server/bridge.js`) **on the same PC** as X-Plane. On startup it auto-copies these three scripts into `/Resources/plugins/FlyWithLua/Scripts/` and keeps them up to date on every launch (it only writes changed/missing files): - **`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. In X-Plane: *FlyWithLua → Reload all Lua script files* (or restart). The log shows `[glass-cockpit] FMS sync active`. No manual copying needed. If you install FlyWithLua *after* the bridge is already running, trigger a re-install without restarting via `POST /api/lua/install`. The current install state is reported under `lua` in `GET /api/health`. The bridge must run on the **same PC** as X-Plane so both see `/Output/fms-sync/`. (The auto-install honours `LUA_SRC_DIR` — the desktop app sets it to the bundled scripts; otherwise it finds `plugins/` itself.) ## 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).