Thread Tools Display Modes
10-17-08, 12:56 AM   #1
lordkarthas
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 35
Trouble making slash commands

This is relevant segment of the code I am using. There are no errors, and the message prints to the chat window. The slash commands just don't work (I get the type /help message).

Code:
function npcIgnore_onLoad()
	SlashCmdList["NPCIGNORE"] = npcIgnore_ChatCommand;
	SLASH_NPCIGNORE1 = "/npcignore";
	SLASH_NPCIGNORE2 = "/npci";
	ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_SAY", npcChatFilter);
	ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_WHISPER", npcChatFilter);
	ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_EMOTE", npcChatFilter);
	DEFAULT_CHAT_FRAME:AddMessage("NPCIgnore is loaded.");
end
Yes, the function does exist.
  Reply With Quote
10-17-08, 01:09 AM   #2
Maul
Ion Engines, Engage!
 
Maul's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 401
Originally Posted by lordkarthas View Post
Yes, the function does exist.
Where in relation to that function does it exist? Before or after? If it is a local function, it needs to be before that function in your post.

local function npcIgnore_ChatCommand()

end


^
^
^
function npcIgnore_onLoad()

end
__________________

Twitter: @IonMaul | Windows Live: [email protected] | Google Talk: [email protected]
  Reply With Quote
10-17-08, 01:12 AM   #3
lordkarthas
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 35
Originally Posted by Maul View Post
Where in relation to that function does it exist? Before or after? If it is a local function, it needs to be before that function in your post.

local function npcIgnore_ChatCommand()

end


^
^
^
function npcIgnore_onLoad()

end
It is before. It does have the signature "function npcIgnore_chatCommand(msg)", if that makes any difference.

EDIT: the placement shouldn't matter, since the function would be added anyway before the OnLoad event fired.

Last edited by lordkarthas : 10-17-08 at 01:20 AM.
  Reply With Quote
10-17-08, 01:42 AM   #4
Cirk
A Cobalt Mageweaver
 
Cirk's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 226
Do you see the "NPCIgnore is loaded" message Lordkarthas? (i.e., is the addon actually loading properly - Buggrabber + Bugsack will help there too).

The other thing you can try is inside the game, do /run ChatFrame1:AddMessage(tostring(SlashCmdList["NPCIGNORE"])) and see if it has a valid entry (should print something like "function:#####").

-- Cirk
__________________
Cirk's Addons
  Reply With Quote
10-17-08, 01:46 AM   #5
lordkarthas
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 35
Originally Posted by Cirk View Post
Do you see the "NPCIgnore is loaded" message Lordkarthas? (i.e., is the addon actually loading properly - Buggrabber + Bugsack will help there too).

The other thing you can try is inside the game, do /run ChatFrame1:AddMessage(tostring(SlashCmdList["NPCIGNORE"])) and see if it has a valid entry (should print something like "function:#####").

-- Cirk
The "NPCIgnore is loaded." message appears, there are no errors, and the script you provided returns nil.
  Reply With Quote
10-17-08, 01:57 AM   #6
Cirk
A Cobalt Mageweaver
 
Cirk's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 226
Originally Posted by lordkarthas View Post
The "NPCIgnore is loaded." message appears, there are no errors, and the script you provided returns nil.
Hmmm, that means that as far as the SlashCmdList is concerned, you don't have anything registered there fore "NPCIGNORE".

So, options:
1. Using the previous script, print out the values of npcIgnore_ChatCommand, SLASH_NPCIGNORE1, SLASH_NPCIGNORE2. (i.e., look and see if any of those got foobar'd).
2. Try with something like
Code:
SlashCmdList["NPCIGNORE"] = function(text) npcIgnore_ChatCommand(text) end;
Which should at least get you a valid function in the SlashCmdList, and then you can try and debug from there.

Hope that helps
__________________
Cirk's Addons
  Reply With Quote
10-17-08, 02:19 AM   #7
lordkarthas
An Aku'mai Servant
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 35
#2 helped. I was looking for npcIgnore_ChatCommand, but the function was named npcIgnore_chatCommand. Stupid case-sensitivity. Thanks for your help.
  Reply With Quote
10-17-08, 08:32 AM   #8
Maul
Ion Engines, Engage!
 
Maul's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 401
Originally Posted by lordkarthas View Post
EDIT: the placement shouldn't matter, since the function would be added anyway before the OnLoad event fired.
Actually, for local functions/values it does matter
__________________

Twitter: @IonMaul | Windows Live: [email protected] | Google Talk: [email protected]
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Trouble making 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