--- title: RegisterEvent summary: Register a Lua callback, interpret its arguments and guard against obsolete contexts. section: reference kind: api status: reference tags: ["X4","modding","register","event"] sources: ["https://wiki.egosoft.com/X4%20Foundations%20Wiki/Modding%20Support/"] --- ## Return value | Type | Meaning | | --- | --- | | [`unknown`](wiki:type-results) | Registration return is not established. Callback arguments belong to the specific event, rather than RegisterEvent itself. | [Types and methods](wiki:types) ## Observed form Layer: game Lua UI. `name` identifies the received event; `callback` processes its arguments. ```lua RegisterEvent(name, callback) ``` ## Example reply from MD The first argument is intentionally ignored in the example. The payload is the second argument on this `raise_lua_event` route. Do not apply that signature to every internal game event without checking its contract. ```lua RegisterEvent("Wiki.Pong", function(_, payload) if payload ~= "pong" then return end -- Ответ распознан. При необходимости обновите своё состояние. end) ``` **What happens:** A callback is registered for Wiki.Pong. With payload = "pong" it reaches the comment; this example has no further action or printed output. ## Lifecycle Do not install a new handler on every frame. Old adapter callbacks may need a current-instance check after replacement. Instance validity and window cleanup must follow the UI lifecycle: [Lua UI](wiki:lua-ui).