--- title: Lua ↔ MD event exchange summary: A complete request route from the UI to Mission Director and a reply back to Lua. section: ui kind: example status: example tags: ["X4","modding","md","lua","bridge"] sources: ["https://wiki.egosoft.com/X4%20Foundations%20Wiki/Modding%20Support/"] --- ## Exchange directions | Direction | Function or condition | | --- | --- | | Lua → MD | `AddUITriggeredEvent(screen, control, payload)` | | MD receiver | `event_ui_triggered`, with `event.param3` in this contract | | MD → Lua | `raise_lua_event` | | Lua receiver | `RegisterEvent(name, callback)` | Names must match exactly. Register the receiver before sending if a reply can arrive immediately. ## Lua subscription and request The example assumes the UI file is already registered through the manifest. It illustrates the call form, not universal world readiness. In a real mod, send only at an established point in both UI and MD lifecycles. ```lua local received = false RegisterEvent("Wiki.Pong", function(_, payload) received = payload == "pong" end) AddUITriggeredEvent("WikiBridge", "ping", "hello") ``` ## MD handling and reply Insert this fragment in your script's `cues`. It matches screen/control, validates the simple hello payload and sends the named pong reply. ```xml ``` ## When an exchange becomes an operation Validate input types and object existence before a game effect. Handle repeated clicks separately for actions that create objects or spend money. Show success after actual execution. Assemble complete multipart replies before replacing a displayed list. See [custom windows](wiki:create-ui) and [AddUITriggeredEvent](wiki:add-ui-triggered-event).