Hi all
My use case is I need to add the itemID of the item under the mouse to a table using a keybind.
If the item is already listed a fail message must print, otherwise add the itemID to the table.
Chunk of pseudo code;
Lua Code:
local itemName, itemLink
local TableOfItems = {}
local function addItemToTable (itemID)
for k, v in pairs(TableOfItems) do
if v == itemID then
print("Item already listed")
else
table.insert(TableOfItems, 1, itemID)
print("Item added to list")
end
end
end
local btn = CreateFrame("BUTTON", "myTest")
SetBindingClick("SHIFT-BUTTON1", "myTest","b1")
btn:SetScript("OnClick", function(self, button)
if button == "b1" then
GameTooltip:HookScript('OnTooltipSetItem', function(self)
local _, itemLink = self:GetItem()
local itemID = tonumber(strmatch(itemLink, "item:(%d+):"))
addItemToTable(itemID)
end)
end
end)
As the hover link spams I run the risk of having the first itemID added thus printing out the success message, yet the second and subsequent itemID fail messages will spam chat.
Idealy I would use the binding F5-BUTTON1 to operate on up/release to fire the
addItemToTable function one time only.