Thread Tools Display Modes
10-19-13, 04:27 PM   #1
Bloodier
A Fallenroot Satyr
Join Date: Mar 2012
Posts: 20
Help with Slash Command implementation

I'm creating a simple addon that shows information like XP to level up on the chat. It's called by typing /minXP. I have the following code (using an .xml to be able to use OnLoad), but the game keeps throwing an unknown command error each time I call it.

Code:
local function cmdHandler(msg, editbox) 
	showXP();
end

function MinimalXP_OnLoad()
	SLASH_MINXP1= "/minXP";
	SlashCmdList["minimalXP"] = cmdHandler;	
end

Last edited by Bloodier : 10-19-13 at 04:35 PM.
  Reply With Quote
10-19-13, 04:38 PM   #2
Clamsoda
A Frostmaul Preserver
Join Date: Nov 2011
Posts: 269
Here is a basic outline of a pure Lua implementation of custom slash commands.

Note: The numbers go from 1 to n.
Note: For this implementation, I have used an anonymous function, but you can certainly point to an already existing one (showXP in your case).
Note: FUNCTIONNAME is arbitrary; make sure it is unique. I typically name them: "CLAMRAIDLOCKOUTS" or "CLAMXP", et cetera.

Code:
SLASH_FUNCTIONNAME1 = "/command"
SLASH_FUNCTIONNAME2 = "/othercommand"
SLASH_FUNCTIONNAMEn = "/anothercommand"
SlashCmdList["FUNCTIONNAME"] = function()
    -- Code here.
end

Last edited by Clamsoda : 10-19-13 at 05:42 PM.
  Reply With Quote
10-19-13, 05:07 PM   #3
Bloodier
A Fallenroot Satyr
Join Date: Mar 2012
Posts: 20
Put it that way, still getting the error
Code:
SLASH_MINXP1= "/minXP";
	SlashCmdList["MINXP"] = showXP();
  Reply With Quote
10-19-13, 05:22 PM   #4
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,360
Remove the () from your function name.
You need the function reference not a function call.
  Reply With Quote
10-20-13, 04:13 AM   #5
Bloodier
A Fallenroot Satyr
Join Date: Mar 2012
Posts: 20
Now working, thank you
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Help with Slash Command implementation


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off