--- title: GetComponentData, GetMacroData and GetWareData summary: Choose the query target, read several properties and preserve Lua result positions. section: ui kind: guide status: reference updated: 2026-10-27 tags: ["X4","modding","lua","data","queries"] sources: ["https://chemodun.github.io/x4/modding-support/ui-modding/lua-globals/","https://www.lua.org/manual/5.1/manual.html","https://github.com/chemodun/X4-LuaLSAddon"] --- ## Choose the correct identifier | Function | First argument | Result | | --- | --- | --- | | `GetComponentData(component, ...)` | Existing component handle in UI | One value per requested key | | `GetMacroData(macro, ...)` | `string`: macro template name | One value per requested key | | `GetWareData(wareID, ...)` | `string`: ware ID | One value per requested key | These belong to X4 UI Lua, not standard Lua or MD. A C pointer, macro name and ware ID are not interchangeable. Accepted keys depend on the function and game version. Case matters: wares have `groupName`, not `groupname`. Source cards list the full key sets. Call reference cards: [GetComponentData](wiki:api-lua-getcomponentdata-466ba6e8), [GetMacroData](wiki:api-lua-getmacrodata-53e483cc), [GetWareData](wiki:api-lua-getwaredata-e67f517f). ## A ware query example In a running X4 addon context: ```lua local wareName, volume = GetWareData("energycells", "name", "volume") if type(wareName) == "string" and type(volume) == "number" then DebugError("[WIKI] ware=" .. wareName .. "; volume=" .. tostring(volume)) end ``` **Effect:** the first result goes into `wareName`, the second into `volume`. With the expected types, a diagnostic line contains the localized name and retrieved volume. Exact values depend on game data and mods; no fixed name or number is promised. The general contract is `any, ...` because the key determines the type. This query expects `string` and `number`; other keys need not have those types. An unknown key can yield `nil` in its position and an engine diagnostic. ## Multiple values are not a table Independent plain Lua example, without the game: ```lua local function sample() return "Demo", nil, 4 end local title, missing, amount = sample() local first = sample() ``` **Values:** `title == "Demo"`, `missing == nil`, `amount == 4`, `first == "Demo"`. Multiple variables preserve positions. One variable receives the first result. Do not treat a `{...}` list containing an intermediate `nil` as a dense array for `ipairs`. ## Continue in practice For components, establish a valid UI handle source and lifetime first. Macros need no live instance but do need a valid template name. Check keys and versions, then types before arithmetic or formatting. These examples were not run in game; the source author's research is not presented as our test. Editor assistance: [X4-LuaLSAddon](https://github.com/chemodun/X4-LuaLSAddon). These are Lua Language Server definitions, not executable mod files. Continue with [types](wiki:types), [Lua and C identifiers](wiki:ids-and-precision) and [UI/MD](wiki:md-lua-bridge).