WoWInterface

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

Elariah 06-25-09 05:39 AM

Slash Commands
 
I'm trying to make a mode, simple to give me some more slash commands. I've created the .toc and a .lua file as per what I've seen in other mods.

The .lua file just contains the following
Code:

SLASH_TOGGLEHELM = "/toggleHelm"
SLASH_TOGGLECLOAK = "/toggleCloak"

SlashCmdList["toggleHelm"] = toggleHelm()
SlashCmdList["toggleCloak"] = toggleCloak()

function toggleHelm()
    ShowHelm(not ShowingHelm())
end

function toggleCloak()
    ShowCloak(not ShowingCloak())
end

But for some reason WoW doesn't recognise these commands. What am I doing wrong? From what I've seen at wowwiki.com this should just work.

Slakah 06-25-09 05:50 AM

Code:

SlashCmdList["toggleHelm"] = toggleHelm()
SlashCmdList["toggleCloak"] = toggleCloak()

Becomes
Code:

SlashCmdList["TOGGLEHELM"] = toggleHelm
SlashCmdList["TOGGLECLOAK"] = toggleCloak


Selite 06-25-09 05:50 AM

Don't you have to use caps in the line

Code:

SlashCmdList["BLAH"] = whatever()
You could try this block of code;

Code:

TOGGLE_HELM1 = "/togglehelm"
SlashCmdList["TOGGLE_HELM"] = function()
    ShowHelm(not ShowingHelm())
end
TOGGLE_CLOAK1 = "/togglecloak"
SlashCmdList["TOGGLE_CLOAK"] = function()
    ShowCloak(not ShowingCloak())
end

Not sure if they'll work, as I am super tired, and they are dry coded.

EDIT : See above post, it's more right.

Elariah 06-30-09 03:18 AM

This is the entire lua file. But this doesn't work. It doesn't seem to recognise the / commands at all.

Code:

SLASH_TOGGLEHELM = "/toggleHelm"
SLASH_TOGGLECLOAK = "/toggleCloak"

SlashCmdList["TOGGLEHELM"] = toggleHelm
SlashCmdList["TOGGLECLOAK"] = toggleCloak

function toggleHelm()
    ShowHelm(not ShowingHelm())
end

function toggleCloak()
    ShowCloak(not ShowingCloak())
end


xConStruct 06-30-09 03:25 AM

Code:

SLASH_TOGGLEHELM1 = "/toggleHelm"
SLASH_TOGGLECLOAK1 = "/toggleCloak"

I think, the 1's are important.
Also you should move your function-definitions at the top of the file, because at the moment where you use them in SlashCmdList they are "nil" / not defined.

Slakah 06-30-09 04:48 AM

Quote:

Also you should move your function-definitions at the top of the file, because at the moment where you use them in SlashCmdList they are "nil" / not defined.
They're global functions so it wont make a difference.

Akryn 06-30-09 05:50 AM

Quote:

Originally Posted by Slakah (Post 145422)
They're global functions so it wont make a difference.

Yes it will; since the reference will be nil when the code runs, it doesn't matter how they're defined later. You're thinking of a slightly different compile-time error; but in this case the code is top-level and those lines will actually *run* while the function names are still nil references.

However, it would be better if they were not global anyway:

Code:

local function toggleHelm()
    ShowHelm(not ShowingHelm())
end

local function toggleCloak()
    ShowCloak(not ShowingCloak())
end


SLASH_TOGGLEHELM1 = "/toggleHelm"
SLASH_TOGGLECLOAK1 = "/toggleCloak"

SlashCmdList["TOGGLEHELM"] = toggleHelm
SlashCmdList["TOGGLECLOAK"] = toggleCloak



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

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