View Single Post
08-04-20, 08:06 PM   #10
Walkerbo
A Cobalt Mageweaver
 
Walkerbo's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 233
Hi all

@Rilgamon, I didn't even think of that, I've been so focused on getting and using the hover to get the itemID that even the simplest of things passed over my head; thanks for reminding me

@Fizzlemizz, I have tried your code however I still have the exact same issues.
I have to /reload after entering world for the first time to get the button clicks to work, and, the list is still empty when I /qwe, I have also got the SavedVariables lua open so I can see if the itemIDs are saved on /reload just to ensure my /qwe was not working properly.
I repaced my orriginal addItemToTable function with your chunk and I also renamed my table, button and vars, (i went a bit overboard with the names).

Here is my current code;
Lua Code:
  1. local myTestingKeybindingItemName, myTestingKeybindingItemLink, myTestingKeybindingItemID
  2.  
  3.     if not myTestingKeybindingTableOfItems then
  4.         myTestingKeybindingTableOfItems = {}
  5.     end
  6.  
  7. local function addItemToTable(itemLink)
  8.     local found
  9.     for k, v in pairs(myTestingKeybindingTableOfItems) do
  10.         if v == itemLink then
  11.             print("Item all ready listed")
  12.             found = true
  13.             break
  14.         end
  15.     end
  16.     if not found then
  17.         table.insert(myTestingKeybindingTableOfItems, 1, itemLink)
  18.         print("Item added to list",itemLink)
  19.     end
  20. end
  21.  
  22. SLASH_MYTEST1 = "/qwe"
  23. function SlashCmdList.MYTEST(msg, editbox)
  24.     if #myTestingKeybindingTableOfItems == 0 then
  25.         print("empty table")
  26.     else
  27.         for k, v in pairs(myTestingKeybindingTableOfItems) do
  28.             print("item", k, v)
  29.         end
  30.     end
  31. end
  32.  
  33. local myTestingKeybindingButton = CreateFrame("BUTTON", "myTest")
  34. SetBindingClick("F5", "myTest", "b1")
  35. SetBindingClick("G", "myTest", "b3")
  36. myTestingKeybindingButton:SetScript("OnClick", function(self, button)
  37.     GameTooltip:HookScript("OnTooltipSetItem", function(self)
  38.         myTestItemName, myTestItemLink = self:GetItem()
  39.         myTestItemID = tonumber(strmatch(myTestItemLink, "item:(%d+):"))
  40.         end)
  41.     if button == "b1" then
  42.         addItemToTable(myTestItemLink)
  43.         print("F5 button clicked", myTestItemLink, myTestItemID)
  44.     elseif button == "b3" then
  45.         print("G button clicked")
  46.     end
  47. end)

I still have the issue that I have to /realod before the keybinds work.

How do I ensure that the keybinds are available when I first log in?
  Reply With Quote