Executing skills
I have been messing around with frames a bit and it is going pretty well :)
but i came to a point where i want to execute a skill when i click the frame. I created a frame using CreateFrame() Set a texture using CreateTexture() and assigned it to the frame And then i used the SetScript function to set a OnMouseDown event. Then the dread began: frame needs to be protected. My problem first of all is how? i followed the text on the wiki but i can't seem to get it to work. Second of all, i read that the position and state (hidden/shown) can't be changed. Is there no way around this? Il try to explain with a bit of an example :) The thing i wanted to make is that some buttons show up under certain (combat) situations. So i create all the frames beforehand and hide them (only one atm) Then when the situation happens (a skill procs for example) the corresponding frame needs to be shown. When i click on the frame, the skill needs to be cast and the frame hidden again. Can anyone help me on my way with this? :) |
Hi Arxae,
In order to cast a spell, use an item, run a macro, target a unit, or do anything like that, your frame has to use one of Blizzard’s secure templates. You can make buttons that appear when you enter combat, or appear when you target an enemy while in combat, but you can’t make them appear (or change which ability is on them) when you gain a buff or when a reactive ability becomes available. The conditions you can use to automatically show, hide, or modify secure frames while in combat are the same conditions you can check for in macros. I’d recommend looking at the addon CrowBar for a simple secure button example. States for auto-showing are a little trickier, and I haven’t ever worked with actual button states, but you could parent the button to a secure state driver frame and set up visibility conditions on that. There’s a simple example of that in ImprovedTotemFrame. Looking at action bar addons might also help, though they tend to be pretty complicated. The same goes for the Blizzard UI code. Hope that helps! |
Ive been looking around a bit and i got a (supposedly) protected frame to show using this code:
Code:
local f = CreateFrame("Frame", nil, UIParent, "SecureHandlerClickTemplate") i tried using SetScript but it doesn't work, tried using SetAttribute, but that doesn't work either the button does show up using SetAttribute, but the click event doesn't do anything, i'm using this example from wowpedia: Code:
-- Assume widget is a frame inheriting from SecureHandlerClickTemplate. |
I think the SecureHandlerClickTemplate template is for creating click-cast unit frames, not for making action buttons. Also, to get click handlers your frame must be a Button, not a regular Frame. Try this instead:
Code:
local f = CreateFrame("Button", nil, UIParent, "SecureActionButtonTemplate") Code:
f:SetAttribute( "type1", "spell" ) Code:
f:SetAttribute( "type1", "macro" ) Code:
f:SetAttribute( "type1", "macro" ) Code:
local f = CreateFrame("Button", "MyButton", UIParent, "SecureActionButtonTemplate") Code:
-- SecureActionButtons allow you to map different combinations of modifiers and buttons into |
That is working as i wanted :D
one small problem tho. Whenever i try to use a macro command a spell (your third example) it does the first thing, but just says the second thing (as in /s say :)) in this case: f:SetAttribute( "macrotext1", [[/cast Frost Shock /run MyButton:Hide()]] ) it casts the spell then does ?/run MyButton:Hide() as a /s command ps: thanks so much for the help :D |
Is there actually a newline or a space between the two macro commands?
|
I tried both with space and newline
Newline gives me the weird ?/ error Space makes the button do absolutely nothing :p here are the specific snippets i'm talking about Code:
f:SetAttribute("macrotext1", [[/cast horn of winter /run button:Hide()]]) Code:
f:SetAttribute("macrotext1", [[/cast horn of winter , makes the button unresponsive and ; makes the button only execute the first command |
Try using end. (; sign)
f:SetAttribute("macrotext1", [[/cast horn of winter /;run button:Hide()]]) |
I think you didn't see my edit :) but ive tried that and it didn't work :<
you also had a typo :3 |
New line is added with \n
|
Quote:
i need to let the following command execute 2 actions: Code:
f:SetAttribute("macrotext1", [[/run MyButton:Hide()]]) |
f:SetAttribute("macrotext1", [[/cast horn of winter\n/run button:Hide()]])
|
Quote:
It shows up, but when i click it, nothing happens |
Do you have "Show Lua Errors" enabled in the interface options? I'm thinking it's throwing an error trying to access a frame referenced by a global variable named "button" that doesn't exist.
Quote:
Quote:
|
I have a feeling he's got a random space somewhere, example (for OP mostly):
Will Work Code:
f:SetAttribute("macrotext1", [[ Code:
f:SetAttribute("macrotext1", [[ Code:
f:SetAttribute("macrotext1", "/cast Frost Shock\n/run MyButton:Hide()") |
Quote:
The OP needs to assign the frame to a global variable and use that in the macro. The /run macro command only inherits the global environment, it does not share any upvalues. |
Quote:
2. You didn't fully read and/or understand Akkorian's original post. I've underlined the relevant parts you should re-read: Quote:
|
Hi Arxae,
Sorry, I forgot to add that you also have to register the button for clicks: Code:
f:RegisterForClicks("AnyUp") |
All times are GMT -6. The time now is 04:19 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI