View Single Post
11-20-23, 09:40 AM   #1
Heybarbaruiva
A Murloc Raider
 
Heybarbaruiva's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2016
Posts: 9
Clearing target/running macro on Event

Hey folks, I'm trying to clear the target on the "ACTIONBAR_UPDATE_STATE" event, but no luck.

This is what the macro looks like in-game:

Code:
MYMACRO
/cleartarget [exists]
And this is the portion of my addon dealing with this functionality:

Code:
local ClearTargetBtn = _G.CreateFrame("Button", "ClearTargetBtn", _G.UIParent, "SecureActionButtonTemplate")
ClearTargetBtn:SetAttribute("type", "macro")
ClearTargetBtn:SetAttribute("macrotext", "/run MYMACRO") -- doesn't work
-- ClearTargetBtn:SetAttribute("macrotext", "/cleartarget") -- doesn't work either

local function ClearTargetOnEvent()
  local isReticleTargetingActive = MYADDON.DB.global.reticleTargeting

  if not isReticleTargetingActive then return end
  ClearTargetBtn:Click()
  print("clearing target") -- prints in chat
end

ClearTargetBtn:RegisterEvent("ACTIONBAR_UPDATE_STATE")
ClearTargetBtn:SetScript("OnEvent",ClearTargetOnEvent)
The ClearTargetOnEvent() function is being fired when the event happens and I get the "cleared target" print in chat, but the macro doesn't seem to be running.

Any ideas on what to do here to achieve the expected result, which is clearing the target so the player doesn't have a target selected anymore?

Appreciate you all!

Last edited by Heybarbaruiva : 11-20-23 at 01:05 PM.
  Reply With Quote