Wikia

WoWWiki

Talk:Creating a slash command

101,502pages on
this wiki

Back to page

I can't do it!!!! Edit

Ok, I'm starting work on a simple test addon as a way to get to grips with lua and xml and the other aspects of coding. I've been using WoW UI Designer for it, largely because it's all I have, and I'm not confident enough to hard-code with notepad just yet! Anyway, I want to create a /easyinfo slash command to show the basic UI element of the project (EasyinfoForm), so I did this:

function Easyinfo_OnLoad()
SLASH_EASYINFO1 = "/easyinfo";
SLASH_EASYINFO2 = "/ezi";
SlashCmdList["MYSCRIPT"] = EasyinfoForm:Show();
end

All that happens when I type /easyinfo or /ezi in on wow is that it comes up with a "type /help for a few commands" thing in the console... my command isn't recognised.

I have loaded the addon, it has a current UI number and I didn't typo the command (I tried several times each time I altered the code, embarrasingly it was throwing up an error to begin with because I had put in "Easyinfo_Onload();" instead of "Easyinfo_Onload()")

Thanks in advance. -- Yoda  talk / cont 13:21, 23 March 2007 (EDT)

Hey Yoda. Two things. Change:
SlashCmdList["MYSCRIPT"] = EasyinfoForm:Show();
to
SlashCmdList["EASYINFO"] = EasyinfoForm:Show;
I was tripped up with mine own setup like this. If you say " = function()" instead of " = function", the LUA engine sets the SlashCmdList for your :addon to the function's RESULT rather than name.
Hope that helps. Rihlsul 20:04, 12 April 2007 (EDT)
I know this is over a year old, but it should be this SlashCmdList["EASYINFO"] = EasyinfoForm.Show; -- note, the dot, not the colon Posted by: EGingell (T|C|F) on 04:19, 12 January 2009 (UTC)

Making secondary slash commands Edit

Say I have the function /addon. I want /addon to do a number of things when different values are proceeding it (/addon information for example). Could somebody please explain how do this for me? TuskertheGreat (talk) 04:39, 16 May 2009 (UTC)

There's examples of this very thing here, Extracting info from a slash command. Posted by: EGingell (T|C|F) on 16:16, 16 May 2009 (UTC)
Thanks for that, it helps. I was really just looking at /slash command stuff, which a friend explained to me, but I will definitely refer to that guide if I need to go more in depth. TuskertheGreat (talk) 23:45, 16 May 2009 (UTC)

Setting the handler function to a method of an object Edit

I added a note about this to the article, should I also include a breif discussion about why it should be done like this? Phaqui (talk) 12:45, January 11, 2010 (UTC)

It doesn't have to be done that way. Example:
function Object.slashHandler(msg, chatPromptFrame) -- note, the dot, not the colon
    -- do stuff
end
SlashCmdList["whatever"] = Object.slashHandler -- the same dot-not-colon here.
Posted by: EGingell (T|C|F) on 21:17, January 11, 2010 (UTC)
In your example you wouldn't be able to use self inside the function. There would be no point whatsoever in making that function a part of an object in the first place, you'd just use an "ordinary" function instead. Phaqui (talk) 21:26, January 11, 2010 (UTC)
It's true that you can't use self, but there is a point. Keeping a function inside a table reduces overhead and if your table is global, your function is always available without polluting the global environment; however, this doesn't really apply to slash functions since you can assign an anonymous function to the SlashCmdList table element, it's just in general. I was just making the point that it can be done without making a function that calls another function. Posted by: EGingell (T|C|F) on 23:02, January 11, 2010 (UTC)
Nah, there is no need to elaborate it further; I'm not entirely convinced it even needs a code example -- a simple natural language description of the problem and potential solution would probably be sufficient. In general, people using objects should know the semantics of what they're doing (and if they don't, that explanation belongs in a HowTo on objects, not in every other HowTo). -- foxlit (talk) 09:54, January 12, 2010 (UTC)
Thinking about it, there should definitely be a short explanation, IMO. Anyway, I never intended the note to be more than a reminder. Of course people should know what they're doing. A first thought on an update: Phaqui (talk) 21:31, January 12, 2010 (UTC)
* Be careful when setting the handler function to a method of an object. The handler function won't be called with a
reference to your object. A simple solution is to encapsulate the call inside a dummy function.

Around Wikia's network

Random Wiki