Originally Posted by Kakjens
Maybe a bit more understandable example:
Lua Code:
local darkmoonflasks = { [1] = 124642, --"Darkmoon Draught of Supremacy", [2] = 124659, --"Darkmoon Tincture of Supremacy", [3] = 124646, --"Darkmoon Draught of Flexibility", [4] = 124658, --"Darkmoon Tincture of Flexibility", [5] = 124645, --"Darkmoon Draught of Precision", [6] = 124657, --"Darkmoon Tincture of Precision", [7] = 124648, --"Darkmoon Draught of Divergence", [8] = 124655, --"Darkmoon Tincture of Divergence", [9] = 124647, --"Darkmoon Draught of Alacrity", [10] = 124656, --"Darkmoon Tincture of Alacrity", [11] = 124650, --"Darkmoon Draught of Deftness", [12] = 124653, --"Darkmoon Tincture of Deftness", [13] = 124651, --"Darkmoon Draught of Deflection", [14] = 124652, --"Darkmoon Tincture of Deflection", [15] = 124649, --"Darkmoon Draught of Defense", [16] = 124654, --"Darkmoon Tincture of Defense", } local numFlasks = #darkmoonFlasks local function do_something(itemID) --put here code what you want to do with the item print(itemID) end local wait = {} local cache_writer = CreateFrame('Frame') cache_writer:RegisterEvent('GET_ITEM_INFO_RECIEVED') cache_writer:SetScript('OnEvent', function(self, event, ...) if event == 'GET_ITEM_INFO_RECIEVED' then -- the info is now downloaded and cached local itemID = ... if wait[itemID] then print("received",itemID) do_something(itemID) wait[itemID] = nil end end end) local function normal_loop() --using for instead of ipairs because want to preserve order for index = 1, numFlasks, 1 do local itemID = darkmoonFlasks[index] local name = GetItemInfo(itemID) if name then do_something(itemID) 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)
|
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!