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, GetMacroData, GetWareData.

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. These are Lua Language Server definitions, not executable mod files. Continue with types, Lua and C identifiers and UI/MD.