Thread Tools Display Modes
07-09-19, 02:58 AM   #1
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Convert ItemID's to Item Details

Hi all

I am building a small addon that converts an itemID into an extended itemDetails table.
I have a function that loops through a list of itemID's and gets the full item details which I then insert as a table into another table.

When I check the results in the saved variables file I get a list with only the hearthstone details, all the other entries display only the itemID.

My convert function, (links to my full code are at the bottom of this post)
Lua Code:
  1. -- convert function
  2. local function convertList()
  3. print('convert start')
  4. for k, v inpairs(AAA_FROM_LIST)do
  5. local itemName,
  6. itemLink,
  7. itemRarity,
  8. itemLevel,
  9. itemMinLevel,
  10. itemType,
  11. itemSubType,
  12. itemStackCount,
  13. itemEquipLoc,
  14. iconFileDataID,
  15. itemSellPrice,
  16. itemClassID,
  17. itemSubClassID,
  18. bindType,
  19. expacID,
  20. itemSetID,
  21. isCraftingReagent = GetItemInfo(v)
  22.  
  23. tempItemList = {
  24. itemID = v,
  25. itemName = itemName,
  26. itemLink = itemLink,
  27. itemRarity = itemRarity,
  28. itemLevel = itemLevel,
  29. itemMinLevel = itemMinLevel,
  30. itemType = itemType,
  31. itemSubType = itemSubType,
  32. itemStackCount = itemStackCount,
  33. itemEquipLoc = itemEquipLoc,
  34. iconFileDataID = iconFileDataID,
  35. itemSellPrice = itemSellPrice,
  36. itemClassID = itemClassID,
  37. itemSubClassID = itemSubClassID,
  38. bindType = bindType,
  39. expacID = expacID,
  40. itemSetID = itemSetID,
  41. isCraftingReagent = isCraftingReagent
  42. }
  43. table.insert(AAA_CONVERTED_LIST,1, tempItemList)
  44. end
  45. print('convert end')
  46. end
My results
Lua Code:
  1. AAA_CONVERTED_LIST = {
  2.     {
  3.         ["itemID"] = 52025,
  4.     }, -- [1]
  5.     {
  6.         ["itemID"] = 50717,
  7.     }, -- [2]
  8.     {
  9.         ["itemID"] = 50606,
  10.     }, -- [3]
  11.     {
  12.         ["itemID"] = 50688,
  13.     }, -- [4]
  14.     {
  15.         ["itemID"] = 50639,
  16.     }, -- [5]
  17.     {
  18.         ["itemID"] = 50687,
  19.     }, -- [6]
  20.     {
  21.         ["itemID"] = 50703,
  22.     }, -- [7]
  23.     {
  24.         ["itemID"] = 50650,
  25.     }, -- [8]
  26.     {
  27.         ["itemID"] = 52028,
  28.     }, -- [9]
  29.     {
  30.         ["itemID"] = 52029,
  31.     }, -- [10]
  32.     {
  33.         ["itemID"] = 52026,
  34.     }, -- [11]
  35.     {
  36.         ["itemID"] = 50685,
  37.     }, -- [12]
  38.     {
  39.         ["itemID"] = 50730,
  40.     }, -- [13]
  41.     {
  42.         ["itemID"] = 147561,
  43.     }, -- [14]
  44.     {
  45.         ["itemID"] = 114131,
  46.     }, -- [15]
  47.     {
  48.         ["itemID"] = 114081,
  49.     }, -- [16]
  50.     {
  51.         ["itemID"] = 119229,
  52.     }, -- [17]
  53.     {
  54.         ["itemID"] = 119226,
  55.     }, -- [18]
  56.     {
  57.         ["itemID"] = 139802,
  58.     }, -- [19]
  59.     {
  60.         ["itemID"] = 32240,
  61.     }, -- [20]
  62.     {
  63.         ["itemID"] = 32258,
  64.     }, -- [21]
  65.     {
  66.         ["itemID"] = 32254,
  67.     }, -- [22]
  68.     {
  69.         ["itemID"] = 805,
  70.     }, -- [23]
  71.     {
  72.         ["itemID"] = 9763,
  73.     }, -- [24]
  74.     {
  75.         ["itemID"] = 4496,
  76.     }, -- [25]
  77.     {
  78.         ["itemID"] = 109119,
  79.     }, -- [26]
  80.     {
  81.         ["itemID"] = 109253,
  82.     }, -- [27]
  83.     {
  84.         ["itemID"] = 128650,
  85.     }, -- [28]
  86.     {
  87.         ["itemName"] = "Hearthstone",
  88.         ["iconFileDataID"] = 134414,
  89.         ["bindType"] = 1,
  90.         ["itemSellPrice"] = 0,
  91.         ["itemLink"] = "|cffffffff|Hitem:6948::::::::19:265::::::|h[Hearthstone]|h|r",
  92.         ["itemClassID"] = 15,
  93.         ["itemLevel"] = 1,
  94.         ["itemStackCount"] = 1,
  95.         ["isCraftingReagent"] = false,
  96.         ["expacID"] = 0,
  97.         ["itemRarity"] = 1,
  98.         ["itemMinLevel"] = 0,
  99.         ["itemID"] = 6948,
  100.         ["itemSubClassID"] = 0,
  101.         ["itemEquipLoc"] = "",
  102.         ["itemSubType"] = "Junk",
  103.         ["itemType"] = "Miscellaneous",
  104.     }, -- [29]
  105.     {
  106.         ["itemID"] = 15017,
  107.     }, -- [30]
  108.     {
  109.         ["itemID"] = 6268,
  110.     }, -- [31]
  111.     {
  112.         ["itemID"] = 90555,
  113.     }, -- [32]
  114.     {
  115.         ["itemID"] = 109118,
  116.     }, -- [33]
  117.     {
  118.         ["itemID"] = 828,
  119.     }, -- [34]
  120.     {
  121.         ["itemID"] = 2657,
  122.     }, -- [35]
  123. }
Here is my lua
Here is my toc
Here is my saved variables results

Any help solving this would be great.
  Reply With Quote
07-09-19, 03:14 AM   #2
LanceDH
A Cyclonian
 
LanceDH's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2012
Posts: 41
Haven't fully checked it, but keep in mind that data from GetItemInfo isn't always instantly available. Check the Details section at the WoWpedia page.
I don't know if you have any of those other items, but you're likely to always have a Heartstone, which might be why it's the only one that has data instantly available.
  Reply With Quote
07-10-19, 04:16 AM   #3
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi LanceDH

Thanks for your reply.

You are correct that the hearthstone details are available as it already my bags, so thanks for pointing that out for me.

I also found your link great as it hinted at some other avenues that may hold the answer I am looking for.

Cheers
  Reply With Quote
07-10-19, 02:44 PM   #4
doofus
A Chromatic Dragonspawn
Join Date: Feb 2018
Posts: 158
When I did something similar you got to listen for GET_ITEM_INFO_RECEIVED

if ( event == "GET_ITEM_INFO_RECEIVED" ) then
-- STL_LogTextLine( "STL - GET_ITEM_INFO_RECEIVED " );
local arg1, arg2, arg3, arg4, arg5, arg6 = ...;

--STL_LogTextLine("[" .. tostring(arg1) .. "] [" .. tostring(arg2) .. "] [" .. tostring(arg3) .. "] [" .. tostring(arg4) .. "] [" .. tostring(arg5) .. "] [" .. tostring(arg6) .. "]" );
--RecordLoot(iItemID, "");
AsyncUpdateItems(arg1);
end


and then

local function AsyncUpdateItems(itemID)

local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, iconFileDataID, itemSellPrice, itemClassID, itemSubClassID, bindType, expacID, itemSetID, isCraftingReagent = GetItemInfo(itemString);

end

itemString is already known so you must be ready before the event comes in (have a map or something)

or use the itemID but I do not know off the top of my head would have to dig more to fine it

Last edited by doofus : 07-10-19 at 02:48 PM.
  Reply With Quote
07-12-19, 06:19 PM   #5
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi doofus

Thanks for your reply.
I can see the concept of your chunks but I am still confused.

I have a list of itemID’s that I loop through, then I use GetItemInfo(currentItemID) which then triggers the ‘GET_ITEM_INFO_RECEIVED’ event.

I can use the event to trigger my one shot function myOneShotFunction(currentItemID) to get all the item details as a table that I can then insert into another table.

How do I pause my loop through function until the event triggers and my one shot function completes?

I know that this is probably an easy concept for those that have a coding background but to say that I am a noob when it comes to coding is a massive understatement.


Cheers
  Reply With Quote
07-12-19, 07:33 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
I can't really think of any practical reason why caching this information is necessary. I would honestly loop through the list and run GetItemInfo() on load (ignoring the returns) to force the game to query the items, then run GetItemInfo() again on what specific item I need info on when I need it. Saves a lot of trouble in the long run with negligible if any resource impact.

If your list is really long, you may opt to build a queue.
Lua Code:
  1. local ItemQueue={};
  2. local function AddToQueue(itemid)
  3.     if #ItemQueue<=0 or not GetItemInfo(itemid) then--  Auto-queries server if this is the first entry, otherwise just adds to queue
  4.         table.insert(ItemQueue,itemid);--   Pushes to end of queue
  5.     end
  6. end
  7.  
  8. local QueueFrame=CreateFrame("Frame");
  9. QueueFrame:RegisterEvent("GET_ITEM_INFO_RECEIVED");
  10. QueueFrame:SetScript("OnEvent",function(_,_,itemid)
  11.     if ItemQueue[1]==itemid then--  Server responded to query
  12.         table.remove(ItemQueue,1);--    Shift queue
  13.         while #ItemQueue>0 do-- Loop until empty
  14.             if GetItemInfo(ItemQueue[1]) then-- Check if we have data
  15.                 table.remove(ItemQueue,1);--    Shift queue
  16.             else--  Query was sent
  17.                 break;--    Exit loop
  18.             end
  19.         end
  20.     end
  21. end);

PS: If GetItemInfoInstant() gets you all the info you need, I'd suggest using that instead as all the data that accesses is on the client, so it doesn't need to query the server.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-12-19 at 07:57 PM.
  Reply With Quote
07-13-19, 02:25 AM   #7
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi SDPhantom

Thanks for your reply.

The reason I need to perform these actions is that I already have addon that stores itemID’s only however I want to introduce filters without having to query the server each time I need to update a scroll frame, as this freezes the game each time I scroll.

When I convert all the itemID’s to itemsDetails that should allow me to sort through itemDetails to select all those that are rarity 1.

Your suggestion to query the server first did work, so I can query then I do the convert the list is compete.

I had not seen a queue solution either, so thanks for sharing that

Cheers
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Convert ItemID's to Item Details

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