C_Container. GetContainerItemInfo
Returns information about the item in a bag slot. · description by wowlua
function C_Container.GetContainerItemInfo( containerIndex: BagIndex, slotIndex: number): ContainerItemInfo?Parameters
| name | type | description |
|---|---|---|
containerIndex | BagIndex | The bag's index. |
slotIndex | number | The slot's index in the bag. |
Returns
containerInfo · ContainerItemInfo? · Returns nil if the container slot is empty.
| field | type |
|---|---|
iconFileID | number |
stackCount | number |
isLocked | boolean |
quality | ItemQuality? |
isReadable | boolean |
hasLoot | boolean |
hyperlink | string |
isFiltered | boolean |
hasNoValue | boolean |
itemID | number |
isBound | boolean |
itemName | string |
Blizzard's documentation says it may return nothing.
In wowlua's emulated client
The emulator answers from its model of the bags and from the item's data:
stackCount,isBoundandisLockedcome from the slot, asmock.setBagor a world profile filled it (count,bound,locked).isLockedis also true while the item is on the cursor, afterC_Container.PickupContainerItem.itemName,iconFileIDandqualitycome from the item's data (mock.defineItem(id, { name, icon, quality })), andisReadablefrom itsreadable.hasNoValueis true when the item'ssellPriceis 0, as for the Hearthstone. An item whose data has nosellPricehashasNoValue = false.hyperlinkis the slot's ownlinkif the test gave one, else the data'slink, else a link built the way the client builds one, from the item's name, its quality and the player's level.hasLootandisFilteredare always false.
It returns nil for an empty slot and for a bag that isn't there. After a
loot, an item that went into an empty slot reads as nil until its data
arrives a moment later, as in the client (see BAG_UPDATE).
For an item the test doesn't define, and that wowlua has no data for, it
returns nil, as the client does for an item whose data hasn't arrived.
GetContainerItemID still returns the item's ID. Define every item your
test puts in the bags.
Restrictions
Example
A /junk command that prints the links of the grey items in the bags that a
vendor would buy.
import slash from "wowlua:slash"import print from "wowlua:log" -- The links of the grey items in the bags that a vendor would buy.export function junk(): string[] local links: string[] = {} local poor = Enum.ItemQuality.Poor for bag = Enum.BagIndex.Backpack, Enum.BagIndex.ReagentBag do for slot = 1, C_Container.GetContainerNumSlots(bag) do local info = C_Container.GetContainerItemInfo(bag, slot) if info and info.quality == poor and not info.hasNoValue then table.insert(links, info.hyperlink) end end end return linksend @slash("/junk")local function listJunk() local links = junk() if #links == 0 then print("no junk") else print(`junk: {table.concat(links, " ")}`) endendThe result is ContainerItemInfo?, so check it before reading its fields. In
a --!strict file, reading info.quality without the info and check is
error E2005. A misspelt field, such as info.hyperLink, is error E2003 in
every mode.
Testing code that uses it
Define the items, fill a bag with them, then run the command.
import test, expect from "wowlua:test"import * as mock from "wowlua:mock" @test("/junk lists the grey items a vendor buys")local function listsJunk() mock.defineItem(4865, { name = "Ruined Pelt", quality = 0, sellPrice = 5 }) mock.defineItem(2589, { name = "Linen Cloth", quality = 1, sellPrice = 13 }) mock.defineItem(90001, { name = "Lucky Stone", quality = 0, sellPrice = 0 }) mock.setBag(0, { slots = 16, items = { [1] = { id = 4865, count = 3 }, [2] = 2589, [3] = 90001 }, }) mock.slash("/junk") local shown = table.concat(mock.printed(), "\n") expect(shown).toContain("[Ruined Pelt]") expect(shown).never.toContain("Linen Cloth") expect(shown).never.toContain("Lucky Stone")end @test("an empty slot has no info")local function emptySlot() mock.setBag(0, { slots = 16 }) expect(C_Container.GetContainerItemInfo(0, 1)).toBeNil() expect(C_Container.GetContainerItemInfo(3, 1)).toBeNil()endThe Lucky Stone is grey too, but its sellPrice of 0 makes hasNoValue
true, so /junk leaves it out.
sources
Signature and flags: Blizzard's API documentation (Blizzard_APIDocumentationGenerated) (Container system, camelot 1.60.1). Description: written by wowlua where no documentation describes the entry. Parameter and result notes: warcraft.wiki.gg's API pages ↗, by its contributors, CC BY-SA 4.0 ↗.