Thread Tools Display Modes
06-13-17, 01:25 AM   #1
loff93
A Fallenroot Satyr
Join Date: Apr 2017
Posts: 25
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.

Last edited by loff93 : 06-13-17 at 01:31 AM.
  Reply With Quote
06-13-17, 01:47 AM   #2
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by loff93 View Post
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
__________________

Last edited by lightspark : 06-13-17 at 01:58 AM.
  Reply With Quote
06-13-17, 02:16 AM   #3
loff93
A Fallenroot Satyr
Join Date: Apr 2017
Posts: 25
Originally Posted by lightspark View Post
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

Last edited by loff93 : 06-13-17 at 02:18 AM.
  Reply With Quote
06-13-17, 02:18 AM   #4
lightspark
A Rage Talon Dragon Guard
 
lightspark's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2012
Posts: 341
Originally Posted by loff93 View Post
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.
__________________

Last edited by lightspark : 06-13-17 at 02:22 AM.
  Reply With Quote
06-13-17, 02:30 AM   #5
loff93
A Fallenroot Satyr
Join Date: Apr 2017
Posts: 25
Originally Posted by lightspark View Post

-- 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!
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » How to get item texture path

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off