View Single Post
04-03-23, 01:20 AM   #1
jeroenvo
A Murloc Raider
Join Date: Apr 2023
Posts: 4
Cant get a button click to execute a macro

Hello!

Im new to wow lua scripting and trying to make a addon that executes a macro text on a button click. When i bind a macrotext to a button (/sit as a example) nothing happens when i click it.

I found this example somewhere online:

Code:
local frame = CreateFrame("Frame", "Test", UIParent, "SecureHandlerStateTemplate")
frame:SetSize(40, 40)
frame:SetPoint("TOPLEFT", UIParent, 10, -150)
 
local button = CreateFrame("Button", "TestBtn", frame, "SecureActionButtonTemplate")
button:ClearAllPoints()
button:SetSize(32, 32)
button:SetPoint("CENTER", frame)

local texture = button:CreateTexture("$parent_tex", "BACKGROUND")
texture:SetAllPoints(true)
texture:SetTexture(GetSpellTexture(783))
button.texture = texture
 
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:SetMouseClickEnabled(true)
button:SetAttribute("type1", "macro")
button:SetAttribute("macrotext", "/sit")
 
button:SetScript("PostClick", function(self, arg1)
    print("POSTCLICK: Clicked button=", self:GetName(), "  macroTxt=", self:GetAttribute("macrotext"))
end)
The PostClick function gets called but the /sit is not being executed. Does someone knows what the issue is?
  Reply With Quote