Mixin help

Hello,
Trying to use the Item Mixin, but doesn’t seem to “find” my item.

local AddonName, Addon = ...

local item = {}

Mixin(Item,ItemMixin)

local waitList={};
local normalLoop

function Addon:normalLoop()
    
    item = Item:CreateFromItemID(30817)
    local iname = Item:GetItemName() 
    
    --local iname = C_Item.GetItemInfo(30817)
    
    if iname == nil then    -- item not cached
        print("iname == nil")                    
        waitList[30817]= 4
    else
        local itemid = C_Item.GetItemIDForItemInfo(iname)
        local icount = GetItemCount(itemid)
        print("Info: ", iname==nil, iname, " ", icount, itemid)
    end

end

local ii_frame = ii_frame or CreateFrame("Frame")
ii_frame:RegisterEvent("SPELLS_CHANGED")
ii_frame:RegisterEvent("GET_ITEM_INFO_RECEIVED")

ii_frame:SetScript("OnEvent", function(self, event, ...) --a1, a2, a3)
    Addon.dprint = true;    --needs to be set to true for DebugPrint function to print

    if event == "SPELLS_CHANGED" then
        Addon:normalLoop()
        ii_frame:UnregisterEvent("SPELLS_CHANGED")
    end
    if event == "GET_ITEM_INFO_RECEIVED" then
    
        local itemID = ...
        --local iname = C_Item.GetItemInfo(itemID)
        local iname = Item:GetItemName()
        print("giir: ", iname)
        if waitList[itemID] then
            local icount = GetItemCount(itemID)
            print("received",itemID, icount, iname)
        end
    end

end)    -- end SetScript

If I change the code to use the C_Item.GetItemInfo and other C_Item objects, the code works as expected. Which is good for me, as long as it works. My question is why doesn’t the Mixin items work, for example:

    local iname = Item:GetItemName()
        print("giir: ", iname)

outputs giiir: nil

I am stumped.

You have two sets of Mixins. Item and ItemMixin

The methods from the Item mixin create a table based on ItemMixin and then adds the required information depending on the Item request (CreateFromItemLink, CreateFromBagAndSlot etc.).

1 Like

To expand on that

Mixin(Item,ItemMixin)

Item is a global set of methods you shouldn’t mess with. Mixing ItemMixin into Item could be very unpredictable,

You call Item:Createxxx() to get back an ItemMixin loaded with the required item information.

1 Like

ok, I copied it from a Mixin example I saw somewhere. I will change.

I changed it

local item={}
local Item={}
Mixin(Item, ItemMixin)

But get error "CreateFromItemID is not an object… so I am doing something wrong. Sigh

Thanks.

Don’t do that.

local itemMixin = Item:CreateFromItemID(nnnnn) -- itemMixin is the ItemMixin returned by calling Item
if itemMixin then 
       print(itemMixin:GetItemName())
end

or if you’re not sure if the item has laready been cached then

local itemMixin = Item:CreateFromItemID(itemID)
if itemMixin then 
    itemMixin:ContinueOnItemLoad(function()
       print(itemMixin:GetItemName())
    end)
end
1 Like