WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Help/Support (https://www.wowinterface.com/forums/forumdisplay.php?f=3)
-   -   How to get item texture path (https://www.wowinterface.com/forums/showthread.php?t=55467)

loff93 06-13-17 01:25 AM

How to get item texture path
 
Hey,

Finally done with exams and wanna progress on my addon. I'm quite new to lua but I'm starting to see how it works.

I got a function tha grabs item info, so I get the item name. My issue is that I can't get access to the itemTexture and it doesn't seem like GetItemInfo is actually returning anything but ID/Name of the item? Might be me using it wrong or so.. Could anyone explain how I can for example access Item Path or vendorPrice ?

Code:

 
    local wait = {}
    local cache_writer = CreateFrame('Frame')
    cache_writer:RegisterEvent('GET_ITEM_INFO_RECEIVED')
    cache_writer:SetScript('OnEvent', function(self, event, ...)
        if event == 'GET_ITEM_INFO_RECEIVED' then
            -- the info is now downloaded and cached
            local itemID = ...
            if wait[itemID] then
                --print("received",itemID)
                                testing2(itemID)
                wait[itemID] = nil
            end
        end
    end)
   
    local function normal_loop()
        --using for instead of ipairs because want to preserve order
        for index = 1, numMaterials, 1 do
            local itemID = craftingMaterials[index]
            local name = GetItemInfo(itemID)
                        --local stringtest = GetItemInfo(itemID.itemTexture)
            if name then
                                print(name.itemTexture)
                testing2(name)
            else
                --add item to wait list
                wait[itemID] = {}
            end
        end
    end
   
    local initframe = CreateFrame("Frame", "MyInitFrame", UIParent)
    initframe:RegisterEvent("PLAYER_LOGIN")
    initframe:SetScript("OnEvent", function(self, event, ...)
        if event == "PLAYER_LOGIN" then
            normal_loop()
        end
    end)

I guess I have to do something like
name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink")

To actually store what I need.

lightspark 06-13-17 01:47 AM

Quote:

Originally Posted by loff93 (Post 323755)
I guess I have to do something like
name, link, quality, iLevel, reqLevel, class, subclass, maxStack, equipSlot, texture, vendorPrice = GetItemInfo(itemID) or GetItemInfo("itemName") or GetItemInfo("itemLink")

To actually store what I need.

You guessed it right.

GetItemInfo returns raw values, they aren't packed, it's not a table. So obv there's no itemTexture member of name, name is just a string.

-- edit #1

Lua Code:
  1. local function normal_loop()
  2.     -- guess numMaterials and craftingMaterials are defined elsewhere :p
  3.     for index = 1, numMaterials do
  4.         local itemID = craftingMaterials[index]
  5.         local name, _, _, _, _, _, _, _, _, texture = GetItemInfo(itemID)
  6.         if name then
  7.             print(texture)
  8.         else
  9.             -- you don't write anything to wait[itemID] table
  10.             -- simple true should be enough
  11.             wait[itemID] = true
  12.         end
  13.     end
  14. end

loff93 06-13-17 02:16 AM

Quote:

Originally Posted by lightspark (Post 323756)
You guessed it right.

GetItemInfo returns raw values, they aren't packed, it's not a table. So obv there's no itemTexture member of name, name is just a string.

-- edit #1

Lua Code:
  1. local function normal_loop()
  2.     -- guess numMaterials and craftingMaterials are defined elsewhere :p
  3.     for index = 1, numMaterials do
  4.         local itemID = craftingMaterials[index]
  5.         local name, _, _, _, _, _, _, _, _, texture = GetItemInfo(itemID)
  6.         if name then
  7.             print(texture)
  8.         else
  9.             -- you don't write anything to wait[itemID] table
  10.             -- simple true should be enough
  11.             wait[itemID] = true
  12.         end
  13.     end
  14. end

Awesome, wasn't sure how to write
Code:

local name, _, _, _, _, _, _, _, _, texture = GetItemInfo(itemID)
without storing everything etc. Works really well , but only if the character has already cached the texture.
How do I solve this issue:
When character has already "GET_ITEM_INFO_RECEIVE" the item ID but still needs the texture?
Code:

            if name and texture then
                testing2(name,texture)
            else
                wait[itemID] = {}
            end


lightspark 06-13-17 02:18 AM

Quote:

Originally Posted by loff93 (Post 323757)
Awesome, wasn't sure how to write
Code:

local name, _, _, _, _, _, _, _, _, texture = GetItemInfo(itemID)
without storing everything etc. Works really well , but only if the character has already cached the texture.
How do I solve this issue:
When character has already "GET_ITEM_INFO_RECEIVE" the item ID but still needs the texture?
Code:

wait[itemID] = {}

Just call GetItemInfo again:
Lua Code:
  1. cache_writer:SetScript('OnEvent', function(self, event, ...)
  2.     if event == 'GET_ITEM_INFO_RECEIVED' then
  3.         local itemID = ...
  4.         if wait[itemID] then
  5.             local _, _, _, _, _, _, _, _, _, texture = GetItemInfo(itemID)
  6.             print(texture)
  7.  
  8.             wait[itemID] = nil
  9.         end
  10.     end
  11. end)

-- edit #1

But if you need only icon textures, you're better off using GetItemInfoInstant instead. This way you can avoid this cache voodoo.

loff93 06-13-17 02:30 AM

Quote:

Originally Posted by lightspark (Post 323758)

-- edit #1

But if you need only icon textures, you're better off using GetItemInfoInstant instead. This way you can avoid this cache voodoo.

owww now that is a function can I like. Thanks again, works really well! :)


All times are GMT -6. The time now is 10:00 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI