Thread Tools Display Modes
06-25-09, 05:39 AM   #1
Elariah
Premium Member
 
Elariah's Avatar
Premium Member
Join Date: Jan 2006
Posts: 18
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.
  Reply With Quote
06-25-09, 05:50 AM   #2
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Code:
SlashCmdList["toggleHelm"] = toggleHelm()
SlashCmdList["toggleCloak"] = toggleCloak()
Becomes
Code:
SlashCmdList["TOGGLEHELM"] = toggleHelm
SlashCmdList["TOGGLECLOAK"] = toggleCloak

Last edited by Slakah : 06-25-09 at 05:52 AM.
  Reply With Quote
06-25-09, 05:50 AM   #3
Selite
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 20
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.
  Reply With Quote
06-30-09, 03:18 AM   #4
Elariah
Premium Member
 
Elariah's Avatar
Premium Member
Join Date: Jan 2006
Posts: 18
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
  Reply With Quote
06-30-09, 03:25 AM   #5
xConStruct
A Chromatic Dragonspawn
 
xConStruct's Avatar
AddOn Author - Click to view addons
Join Date: May 2008
Posts: 199
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.
__________________
« Website | GitHub »

Oh hai!
  Reply With Quote
06-30-09, 04:48 AM   #6
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
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.
  Reply With Quote
06-30-09, 05:50 AM   #7
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by Slakah View Post
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

Last edited by Akryn : 06-30-09 at 05:56 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Slash Commands

Thread Tools
Display Modes

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