WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Help with Slash Command implementation (https://www.wowinterface.com/forums/showthread.php?t=48385)

Bloodier 10-19-13 04:27 PM

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


Clamsoda 10-19-13 04:38 PM

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


Bloodier 10-19-13 05:07 PM

Put it that way, still getting the error :(
Code:

SLASH_MINXP1= "/minXP";
        SlashCmdList["MINXP"] = showXP();


Dridzt 10-19-13 05:22 PM

Remove the () from your function name.
You need the function reference not a function call.

Bloodier 10-20-13 04:13 AM

Now working, thank you :)


All times are GMT -6. The time now is 09:57 AM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI