SetBindingMacro does not work while SetBindingSpell does?

So, I have this snippet of code that worked well when it was a SetBindingSpell, but now that I have switched over to using a macro, it just doesn’t fire off. The idea here was to create a series of frames that let me cast spells using the mouse wheel instead of via clicking.

frame = CreateFrame("Button",frameName,UIParent,"SecureHandlerEnterLeaveTemplate")
frame:SetAlpha(.15)
frame:SetPoint(position,0,0)
frame:SetPropagateKeyboardInput(true)
frame:RegisterForClicks("AnyUp","AnyDown")
frame:SetAttribute("type", "macro")
frame:SetNormalTexture((GetSpellTexture(spellName)) or "Interface\\Icons\\INV_Misc_QuestionMark")
frame:SetAttribute("macrotext", "/cast " .. spellName)
frame:SetAttribute("_onenter",[[
	self:SetBindingMacro(true,"MOUSEWHEELUP",self:GetAttribute("macrotext"))
	print(self:GetAttribute("macrotext"))
]])

So, the mouse enters the frame, the binding is set, and then mousewheelup makes it cast the given spell. And “spellName” here could be anything-- Flash of Light for example.

This is what that snippet looked like previously when it worked using just a spell, and not a macro:

frame = CreateFrame("Button",frameName,UIParent,"SecureHandlerEnterLeaveTemplate")
frame:SetAlpha(.15)
frame:SetPoint(position,0,0)
frame:SetPropagateKeyboardInput(true)
frame:RegisterForClicks("AnyUp","AnyDown")
frame:SetAttribute("spell", spellName)
frame:SetNormalTexture((GetSpellTexture(spellName)) or "Interface\\Icons\\INV_Misc_QuestionMark")
frame:SetAttribute("_onenter",[[
	self:SetBindingSpell(true,"MOUSEWHEELUP",self:GetAttribute("spell"))
]])

Any ideas?

Any reason for not using the InsecureActionButtonTemplate and registering for MiddleButtonUp?

local frame = CreateFrame("Button",frameName,UIParent,"InsecureActionButtonTemplate")
frame:SetAlpha(.15)
frame:SetPoint(position,0,0)
frame:SetPropagateKeyboardInput(true)
frame:RegisterForClicks("MiddleButtonUp")
frame:SetAttribute("type", "macro")
frame:SetNormalTexture((GetSpellTexture(spellName)) or "Interface\\Icons\\INV_Misc_QuestionMark")
frame:SetAttribute("macrotext", "/cast " .. spellName)

Is there a reason you’re not just using Blizz’s Click-Casting Interface to bind the spell/macro?

1 Like

Gonna have to explain what you mean by that. Most of what I know comes from spending hours on WoWfandom.

Edit: Oh I see-- I was thinking that was some function I had missed… I am creating my own frames that use the mouse wheel instead of normal clicking, if that wasn’t clear.

MiddleButtonUp is not what I am looking for. I can get the Mouse Wheel to work with the SetBindingSpell but not with SetBindingMacro, and I just dont understand why… Also, tried the InsecureActionButtonTemplate as you suggested and it does work with middlemouse click, but not the mousewheel.

But to answer you more directly, the mouse wheel is able to “click” much more rapidly than a normal click.

1 Like

Should be able to do that with the addon Clique if nothing else.

I actually use Clique, but I don’t think you can bind it to specific frames/buttons… For example, I have Death Grip set to mousewheel down using Hovercast so I don’t have to break my current target, but with that binding, that is ALL I can use mousewheel down for.

Here, I want to be able to use the mouse wheel to “click” custom frames/buttons I make. Think of an additional actionbar.

SetBindingMacro uses an existing named macro or index to an existing macro. Unless you have a macro saved named /cast (whatever spell), that won’t work.

To run a traditional macrotext (macro body), you can use SetBindingClick.

1 Like

So I’ve given this a few tries since the last post, and I was able to get this part working…

frame:SetAttribute("_onenter",[[
	self:SetBindingMacro(true,"MOUSEWHEELUP", "Pal-FoL", "LeftButton")
]])

Where “Pal-FoL” is just /use [@party1] Flash of Light. That said, according to https://wowpedia.fandom.com/wiki/API_SetBindingMacro “true” shouldn’t be necessary here, but I found that without “true” it just wouldn’t work. So, what am I not understanding here?

And then macrotext here–

frame:SetAttribute("_onenter",[[
	self:SetBindingClick(true, "MOUSEWHEELUP", self:GetAttribute("macrotext"), "LeftButton")
]])

– Fails silently without any errors at all. Using print(self:GetAttribute("macrotext")) indicates the macrotext is being read correctly, which is again just: /use [@party1] Flash of Light

I am missing something with the syntax, right?

https://github.com/Gethe/wow-ui-source/blob/live/Interface/FrameXML/RestrictedFrames.lua#L517

SetBindingClick binds a key to click a button, just as SetBindingMacro binds a key to a macro and SetBindingSpell binds a key to a spell. You don’t put the macrotext as an argument in any binding API, you make a secure button with a macrotext and then bind a key to click that button.

local f = CreateFrame("Button", "ClickBindDemo", UIParent, "SecureHandlerEnterLeaveTemplate,SecureActionButtonTemplate")

f:SetSize(50,50)
f:SetPoint("CENTER",-200,0)
f:SetNormalTexture("Interface\\Icons\\INV_Misc_QuestionMark")
f:RegisterForClicks("AnyUp","AnyDown")

f:SetAttribute("type","macro")
f:SetAttribute("macrotext","/run print('this button was \"clicked\"')")

f:SetAttribute("_onenter",[[
  self:SetBindingClick(true,"MOUSEWHEELUP",self:GetName())
]])
f:SetAttribute("_onleave",[[
  self:ClearBindings()
]])

Here it binds MOUSEWHEELUP to the button named ClickBindDemo in its _onenter and clears the binding in the _onleave.

Note that this inherits SecureActionButtonTemplate in addition to SecureHandlerEnterLeaveTemplate. The latter just grants _onenter/_onleave and you probably won’t get full functionality without another template.

While this can be an anonymous button with no name so you could do:

self:SetBindingClick(true,"MOUSEWHEELUP",self)

there are a few places were you need names (I’m thinking frame references but could be misremembering) so it’s probably a good to idea to make /clickable things named.

You’ll also note that actually clicking the button has the same effect as mousewheel up. If you don’t want this behavior I recommend making another button that inherits something like SecureActionButtonTemplate that it’s bound to in the _onenter. If you want a single button to have both the onenter/onleave and click, it’s doable by wrapping the snippet with SecureHandlerWrapScript (or header:WrapScript), but you’ll be making it needlessly hard on yourself since you have to set up a return in the preclick to restore the attributes in the postclick. Just make a separate button if you don’t want an actual click of the button to do the same thing as mousewheel up.

On the true/false, that’s the priority flag. I’m able to use a false in the above SetBindingClick. It’s possible you have another override binding that has it as true so a false isn’t sufficient in your setup.

edit: These are override bindings btw. For better documentation I recommend the SetOverrideBinding pages instead of the regular SetBinding pages:

2 Likes

Thank you for example, Gello. I also appreciate the lengthy explanation. :slight_smile: