View Single Post
04-30-17, 07:42 AM   #15
loff93
A Fallenroot Satyr
Join Date: Apr 2017
Posts: 25
Thumbs up

Originally Posted by Kakjens View Post
Maybe a bit more understandable example:
Lua Code:
  1. local darkmoonflasks = {
  2.     [1] = 124642, --"Darkmoon Draught of Supremacy",
  3.     [2] = 124659, --"Darkmoon Tincture of Supremacy",
  4.     [3] = 124646, --"Darkmoon Draught of Flexibility",
  5.     [4] = 124658, --"Darkmoon Tincture of Flexibility",
  6.     [5] = 124645, --"Darkmoon Draught of Precision",
  7.     [6] = 124657, --"Darkmoon Tincture of Precision",
  8.     [7] = 124648, --"Darkmoon Draught of Divergence",
  9.     [8] = 124655, --"Darkmoon Tincture of Divergence",
  10.     [9] = 124647, --"Darkmoon Draught of Alacrity",
  11.     [10] = 124656, --"Darkmoon Tincture of Alacrity",
  12.     [11] = 124650, --"Darkmoon Draught of Deftness",
  13.     [12] = 124653, --"Darkmoon Tincture of Deftness",
  14.     [13] = 124651, --"Darkmoon Draught of Deflection",
  15.     [14] = 124652, --"Darkmoon Tincture of Deflection",
  16.     [15] = 124649, --"Darkmoon Draught of Defense",
  17.     [16] = 124654, --"Darkmoon Tincture of Defense",
  18. }
  19.  
  20. local numFlasks = #darkmoonFlasks
  21. local function do_something(itemID)
  22.     --put here code what you want to do with the item
  23.     print(itemID)
  24. end
  25.  
  26. local wait = {}
  27. local cache_writer = CreateFrame('Frame')
  28. cache_writer:RegisterEvent('GET_ITEM_INFO_RECIEVED')
  29. cache_writer:SetScript('OnEvent', function(self, event, ...)
  30.     if event == 'GET_ITEM_INFO_RECIEVED' then
  31.         -- the info is now downloaded and cached
  32.         local itemID = ...
  33.         if wait[itemID] then
  34.             print("received",itemID)
  35.             do_something(itemID)
  36.             wait[itemID] = nil
  37.         end
  38.     end
  39. end)
  40.  
  41. local function normal_loop()
  42.     --using for instead of ipairs because want to preserve order
  43.     for index = 1, numFlasks, 1 do
  44.         local itemID = darkmoonFlasks[index]
  45.         local name = GetItemInfo(itemID)
  46.         if name then
  47.             do_something(itemID)
  48.         else
  49.             --add item to wait list
  50.             wait[itemID] = {}  
  51.         end
  52.     end
  53. end
  54.  
  55. local initframe = CreateFrame("Frame", "MyInitFrame", UIParent)
  56. initframe:RegisterEvent("PLAYER_LOGIN")
  57. initframe:SetScript("OnEvent", function(self, event, ...)
  58.     if event == "PLAYER_LOGIN" then
  59.         normal_loop()
  60.     end
  61. end)
Awesome. Thanks!
By the way - thanks to everyone replying to the thread. Totally new to this language, wow addons and this forum and I'm overwhelmed by all the help and fast replies!
  Reply With Quote