Hi Fizzlemizz
Thanks for your code, it is much more legible and easier to follow than mine.
However, it still has the same issue, I have to /reload after logging in to get the keybinds to work.
After much gnashing of teeth, a few print statements and a hell of a lot of experimentation I ended up solving the problem by creating the button itself in a function and then having another frame to run the new function on the player entering the world.
My full solution;
Lua Code:
local myTestingKeybindingItemName, myTestingKeybindingItemLink, myTestingKeybindingItemID
local function addItemToTable(itemLink)
if not myTestingKeybindingTableOfItems then
myTestingKeybindingTableOfItems = {}
end
local found
for k, v in pairs(myTestingKeybindingTableOfItems) do
if v == itemLink then
print("Item all ready listed")
found = true
break
end
end
if not found then
table.insert(myTestingKeybindingTableOfItems, 1, itemLink)
print("Item added to list",itemLink)
end
end
SLASH_MYTEST1 = "/qwe"
function SlashCmdList.MYTEST(msg, editbox)
if #myTestingKeybindingTableOfItems == 0 then
print("empty table")
else
for k, v in pairs(myTestingKeybindingTableOfItems) do
print("item", k, v)
end
end
end
local function keybindingButtonSetUp()
print("*** keybinding setup function fired ***")
local myTestingKeybindingButton = CreateFrame("BUTTON", "WalkerbomyTest")
SetBindingClick("F5", "WalkerbomyTest", "b1")
SetBindingClick("G", "WalkerbomyTest", "b3")
myTestingKeybindingButton:SetScript("OnClick", function(self, button)
if button == "b1" then
addItemToTable(myTestingKeybindingItemLink)
print("F5 button clicked", myTestingKeybindingItemLink, myTestingKeybindingItemID)
elseif button == "b3" then
print("G button clicked")
end
end)
end
GameTooltip:HookScript("OnTooltipSetItem", function(self)
myTestingKeybindingItemName, myTestingKeybindingItemLink = self:GetItem()
myTestingKeybindingItemID = tonumber(strmatch(myTestingKeybindingItemLink, "item:(%d+):"))
print("item under mouse",myTestingKeybindingItemLink)
end)
local myTestingKeybindingFrame = CreateFrame("FRAME", "WalkerboFrame")
myTestingKeybindingFrame:SetScript('OnEvent', function(self, event, ...)
if event == 'PLAYER_LOGIN' then
print("*** Addon Loaded ***")
keybindingButtonSetUp()
end
end)
myTestingKeybindingFrame:RegisterEvent('PLAYER_LOGIN')
There is probaly a more efficent way of achieveing the same result but for now I am happy just to have it working.
The next thing on my list is to have the keybindings show in the bindings menu so users can swap the bindings to a key of their choice.
If I fail at that I will probably be back.
Thank you all for the help