Function to put Spells on Actionbar?
Hi,
I am trying some simple things to learn addon development, and came across with sth i would like to achieve. It doesn't really make sense to do it, but i was wondering if it is possible, cause i couldn't find sth about it on wowprogramming. So, I would like to create an addon, that has a button, and if you click it, it will put specific spells in an actionbar slot. maybe another button to remove all spells from all bars first.. is there some API function I didnt see, or some other ways to achieve that? Please, I dont want any complete code, I just need a hint if its possible, and if yes, push me into the right direction.. i want to learn, not copy / paste ;) thanks in advance chumii |
Sure, PickupSpell and PickupAction (don't let the name fool you; it's not limited to picking up) should be of use. As long as you're not trying to do it in combat it's easy enough. If you need to do it in combat I'm not sure whether that's possible, let alone how.
|
no, not in combat.. will have a look at those, thank you!
|
hmm.. dont want to start a new thread but got another question, kind of related:
if i have a lua table with some spells, like Code:
spells_arms = { Code:
function putSpellsOnBars() Code:
function putSpellsOnBars() |
Yeah, that'll be the best way. You can use the length operator # instead of manually entering the table length. If you're gonna place the spells sequentially you could just use the loop counter spellcount for PlaceAction instead of keeping a separate i. Also, for future reference you'll want to move the table out of the function if possible, so it's only created once instead of each time the function is called.
Code:
local spell_list = { |
Thanks man, that #spell_list saves a lot of work!
i got it running now as I want, and made a simple "UI" for it. But now I got the problem, that its showing up everytime I login to wow. How can I make it only show up via slashcommand? I know how to register a slashcommand, but what would be the function to call? MainFrame:Show(); for example? cause thats not working for me.. I added MainFrame:Hide(); to the onLoad but thats not doing it.. Code:
function MainFrame_OnLoad() |
The SlashCmdList[] value should point to a function that handles the slash command. Basically like this:
Lua Code:
|
Duugu, what you've written won't work, since (a) there is no global "split" alias for the string.split function, only "strsplit", (b) string.split requires the delimiter as the first argument, not the string to be split, and (c) string.split returns a list, not a table. Even if you enclosed it in curly brackets to create a table, which I suppose was your intention, that's rather inefficient anyway. Also, there's no need to delay creating your slash command; you can just do it in the main chunk, outside of any other function. Here's the usual way to handle commands with arguments that doesn't create new tables all the time:
Lua Code:
Other benefits of this approach include: - The user gets the help list no matter what they type, as long as it's not a valid command, instead of limiting them to a few pre-set help commands like "help" and "?". If you limit them, then typing an invalid command (even making a typo, like "hied" instead of "hide") will result in nothing at all happening, which is confusing. - Each command can handle its arguments however it likes, rather than being forced to handle them one word at a time and use more string functions to join them back up if that's not what it wants. |
Also, if you're going to make everything a global (though really, you shouldn't make anything global that doesn't need to be global) you should make sure their names are unique and clearly identify which addon they belong to. "spell_list" and "putSpellsOnBars" don't meet either of those criteria. If another addon author makes globals with the same names -- probably accidentally, as globals are generally avoided -- then one addon will break the other, or both addons will break. And if Blizzard makes a global with the same name, your addon could potentially break the entire interface; this has happened before, when Blizzard leaked a global "_" and the hundreds of addons who authors were lazily leaking globals with the same name caused the entire UI to become tainted and stop working.
|
You guys are awesome, thank you so far! Editing names is a good point, tho I wont ever make this public cause its only for me to learn, but I get your point :)
Macros works now, but the window still shows up on login.. If I type /run CutieRestMainFrame:Hide() it will hide, but I dont want to type that in everytime I login.. Lua Code:
the frame.xml file is edited too, to match the names ofc edit: got it, forgot to call the OnLoad() function inside my frame.xml... but a last little thing i wondered.. is it possible to grey out buttons? I mean like, making them inactive and not clickable? |
Quote:
NameOfTheButton:Enable() NameOfTheButton:SetEnabled(nil/false to disable, true or anything else to enable) Also: NameOfTheButton:SetMotionScriptsWhenDisabled(true|false) ...if you want to keep the OnEnter/OnLeave scripts enabled (eg. to show a tooltip) while the button is disabled. |
Quote:
|
Quote:
|
All times are GMT -6. The time now is 05:37 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI