Thread Tools Display Modes
12-08-09, 01:14 AM   #1
ahhnam
A Murloc Raider
Join Date: Aug 2009
Posts: 6
SlashCmdList help

Recently I've been messing around with lua and most of the stuff I can understand by looking at websites and such but something about these slashcmdlist that I just don't understand. What I am trying to do here is to make some ingame slash commands that will enable/disable parts of an addon.

This works fine with no errors ingame however it just doesn't seem to change testing1 or testing2 to true or false, so I am pretty sure I'm doing something wrong here but can't seem to figure out what it is.

Part of this might not make sense cause it's late over here but I think anyone that has to patience to read this through thank you.


Code:
local testing1 = true
local testing2 = true

SLASH_TEST1 = "/test"
SlashCmdList["TEST"] = function(msg)
	if(msg) then
		local command = msg:match("^(%S*)%s*(.-)$");
		command = string.lower(command)
		
			if (command == "testing1") then
				if testing1 == true then
					testing1 = false
					print("testing1 set to false")
				else
					testing1 = true
					print("testing1 set to true")
				end		
			elseif (command == "testing2") then
				if testing2 == true then
					testing2 = false
					print("testing2 set to false")
				else
					testing2 = true
					print("testing2 set to true")
				end
			end
	end
end
  Reply With Quote
12-08-09, 01:48 AM   #2
nightcracker
A Molten Giant
 
nightcracker's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 716
lua Code:
  1. local testing1 = true
  2. local testing2 = true
  3.  
  4. SLASH_TEST1 = "/test"
  5. SlashCmdList["TEST"] = function(msg)
  6.     msg = string.lower(msg)    
  7.     if (msg == "testing1") then
  8.         if testing1 then
  9.             testing1 = false
  10.             print("testing1 set to false")
  11.         else
  12.             testing1 = true
  13.             print("testing1 set to true")
  14.         end    
  15.     elseif (msg == "testing2") then
  16.         if testing2 then
  17.             testing2 = false
  18.             print("testing2 set to false")
  19.         else
  20.             testing2 = true
  21.             print("testing2 set to true")
  22.         end
  23.     end
  24. end
__________________
Three things are certain,
Death, taxes and site not found,
You, victim of one.
  Reply With Quote
12-08-09, 05:06 AM   #3
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
lua Code:
  1. local testing1 = true
  2. local testing2 = true
  3.  
  4. SLASH_TEST1 = "/test"
  5. SlashCmdList["TEST"] = function(msg)
  6.                    msg = string.lower(msg)    
  7.  
  8.                    if msg == "testing1" then
  9.                        testing1 = not testing1
  10.                        print(string.format("testing1 set to %s", (testing1 and "true" or "false")))
  11.                    elseif msg == "testing2" then
  12.                        testing2 = not testing2
  13.                        print(string.format("testing2 set to %s", (testing2 and "true" or "false")))
  14.                    end
  15.                end
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
12-08-09, 11:59 AM   #4
Coren
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2006
Posts: 6
I think you want to evaluate the input
"/test testing 1"
to
testing1 = not testing1;

I would think that your match fails.
print(command or "<no match>");
should give you details...
From a quick glance, I don't think you want that capital S?

I'd try:
"^([^%s]*)%s*(%d-)$"
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » SlashCmdList help


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