Quantcast
Slash Commands - WoWInterface
Thread Tools Display Modes
04-02-16, 06:55 PM   #1
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
Slash Commands

I've read so many posts and tutorials on this but I can't find the fault in my code... i have

Code:
SlashCmdList["RAIDLOCKREPORT"] = DEFAULT_CHAT_FRAME:AddMessage("Working");
SLASH_RAIDLOCKREPORT1 = "/raidlockreport";
SLASH_RAIDLOCKREPORT2 = "/rlr";
When I run the code I get "Type '/help' for a listing of a few commands."
  Reply With Quote
04-02-16, 07:48 PM   #2
Dridzt
A Pyroguard Emberseer
 
Dridzt's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2005
Posts: 1,257
Originally Posted by suipsyco View Post
I've read so many posts and tutorials on this but I can't find the fault in my code... i have

Code:
SlashCmdList["RAIDLOCKREPORT"] = DEFAULT_CHAT_FRAME:AddMessage("Working");
SLASH_RAIDLOCKREPORT1 = "/raidlockreport";
SLASH_RAIDLOCKREPORT2 = "/rlr";
When I run the code I get "Type '/help' for a listing of a few commands."
Code:
SlashCmdList["RAIDLOCKREPORT"] = function() 
    DEFAULT_CHAT_FRAME:AddMessage("Working"); 
end
SLASH_RAIDLOCKREPORT1 = "/raidlockreport";
SLASH_RAIDLOCKREPORT2 = "/rlr";
Drycoded.
Edit: Assuming the addon where you have that code is actually loading without errors.
  Reply With Quote
04-02-16, 08:29 PM   #3
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
Thanks that worked! So am I to understand that SlashCmdList[""] need to be a function then?
  Reply With Quote
04-02-16, 08:57 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
A function with a single string parameter if needed.

It could be:
Code:
SlashCmdList["RAIDLOCKREPORT"] = function(msg) 
    if msg then
        DEFAULT_CHAT_FRAME:AddMessage(msg) 
    else
        DEFAULT_CHAT_FRAME:AddMessage("Working") 
    end
end
SLASH_RAIDLOCKREPORT1 = "/raidlockreport";
SLASH_RAIDLOCKREPORT2 = "/rlr";
if you type "/rlr 123" it would print 123.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
04-02-16, 09:04 PM   #5
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
Gotcha, so, the slash command is working, but the goal of the slash command is to show the frame again after its been closed. Once again, everywhere I check, I need to use the Show() function for the frame. When I run this code, the "Working" message still shows so i know that the slash is working, but the frame doesn't show and when I hit enter to send the command the text stays in the bar.

Also, aside from the book, where can i find these answers so i don't have to ask so often? Google is failing me only giving me poorly descriptive API pages...

Code:
SlashCmdList["RAIDLOCKREPORT"] = function() 
    DEFAULT_CHAT_FRAME:AddMessage("Working");
    UIConfig:Show()
end
SLASH_RAIDLOCKREPORT1 = "/raidlockreport";
SLASH_RAIDLOCKREPORT2 = "/rlr";


local UIConfig = CreateFrame("Frame", "MUI_BuffFrame", UIParent, "BasicFrameTemplateWithInset");
  Reply With Quote
04-02-16, 09:28 PM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
wowprogramming.com and wowpedia.org are two good sites.

You should be getting an error which is why you're seeing this behaviour so, you need to turn on "Display lua Errors" in the Interface\Help options or better yet get
BugGrabber and BugSack

Anything local needs to be declared before it is called so in this case to create a toggle,
Code:
local UIConfig = CreateFrame("Frame", "MUI_BuffFrame", UIParent, "BasicFrameTemplateWithInset");
UIConfig:SetSize(50, 50)
UIConfig:ClearAllPoints()
UIConfig:SetPoint("CENTER")

SlashCmdList["RAIDLOCKREPORT"] = function() 
    DEFAULT_CHAT_FRAME:AddMessage("Working");
    if not UIConfig:IsShown() then
        UIConfig:Show()
    else
        UIConfig:Hide()
    end
end
SLASH_RAIDLOCKREPORT1 = "/raidlockreport";
SLASH_RAIDLOCKREPORT2 = "/rlr";
Edit: Updated so you can see something.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-02-16 at 09:36 PM.
  Reply With Quote
04-02-16, 09:44 PM   #7
suipsyco
A Deviate Faerie Dragon
Join Date: Apr 2016
Posts: 13
So its the location where I put the slash command that's messing it up?, I do have the frame described further in the code. I read somewhere that the slash commands needed to be declared in the beginning of the code
  Reply With Quote
04-02-16, 09:48 PM   #8
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,259
It's technically the location of the local declaration but symantics .

The slash command can be anywhere, I tend to place them at the bottom of my main code page.

Pretty much all of the API documentation is user generated and times and the API change but the documentation doesn't always get updated along with the changes which makes WoWInterface an extremely useful site.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 04-03-16 at 12:08 AM.
  Reply With Quote
04-03-16, 08:21 PM   #9
Uitat
A Flamescale Wyrmkin
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 141
this is the simplest way i found

simplest way i found

Code:
SLASH_COMMAND1 = "/text"
SLASH_COMMAND2 = "/longtext"
SlashCmdList["COMMAND"] = function()
	Activate_This_Function()
end
__________________
  Reply With Quote
04-03-16, 09:07 PM   #10
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 428
The compiler reads your code like a book, from start to finish. If you don't declare variables before you use them, they'll always be nil (unless they exist in a higher scope). As an example:

Lua Code:
  1. -- myVariable is declared, but is nil
  2. local myVariable
  3.  
  4. -- this function can access myVariable, because myVariable was declared beforehand,
  5. -- even though myVariable has no value assigned to it.
  6. local function whatIsMyVariable()
  7.     print("My variable is: ", myVariable)
  8. end
  9.  
  10. whatIsMyVariable()
  11. -- prints: My variable is nil
  12.  
  13. myVariable = "abc"
  14. -- myVariable is given a value
  15.  
  16. whatIsMyVariable()
  17. -- prints: My variable is abc

Lua Code:
  1. -- this function has no idea what myVariable is,
  2. -- because it didn't exist before this function was declared.
  3. local function whatIsMyVariable()
  4.     print("My variable is: ", myVariable)
  5. end
  6.  
  7. local myVariable
  8.  
  9. whatIsMyVariable()
  10. -- prints: My variable is nil
  11.  
  12. myVariable = "abc"
  13. -- myVariable is given a value
  14.  
  15. whatIsMyVariable()
  16. -- prints: My variable is nil
__________________

Last edited by MunkDev : 04-03-16 at 09:11 PM.
  Reply With Quote
04-03-16, 09:17 PM   #11
Uitat
A Flamescale Wyrmkin
 
Uitat's Avatar
AddOn Author - Click to view addons
Join Date: May 2011
Posts: 141
ok this is something i used for my config base frame now your main frame to hide all would be in the place of config_BaseFrame

also note i nested this to my topFrame and the toggle for it was a button, when i clicked the button it activated this code, just a little example, most here could find a cleaner way to do it but this worked for me...

if you want to gut my original code for your own use you can check it out at Project Deranjata here on WI. the file it is located in is config.lua


Code:
function MyAddon_ShowOptionFrame()
	--[[ Does the frame already exist?]]
	if not Config_BaseFrame then
		--[[ Nope. Create it now:]]
		CreateFrame("frame", "Config_BaseFrame", UIParent)
		Config_BaseFrame:SetWidth(1024)
		Config_BaseFrame:SetHeight(512)
		Config_BaseFrame:SetPoint("CENTER", UIParent,"CENTER")
		Config_BaseFrame:SetFrameStrata("HIGH")
		--[[	MAKE THE FRAME MOVEABLE ON RIGHT CLICK]]
		Config_BaseFrame:SetMovable(true)
		Config_BaseFrame:EnableMouse(true)
		Config_BaseFrame:SetScript("OnMouseDown", function(self, button)
			if button == "RightButton"
				and not self.isMoving
				then
					self:StartMoving()
					self.isMoving = true
				end
			end)
			Config_BaseFrame:SetScript("OnMouseUp", function(self, button)
				if button == "RightButton"
					and self.isMoving
					then
						self:StopMovingOrSizing()
						self.isMoving = false
					end
				end)
				Config_BaseFrame:SetScript("OnHide", function(self)
					if ( self.isMoving )
						then
							self:StopMovingOrSizing()
							self.isMoving = false
						end
					end)


				else
					--[[ frame already exists, so toggle it.]]
					Config_BaseFrame:SetShown(not Config_BaseFrame:IsShown())
				end
__________________

Last edited by Uitat : 04-03-16 at 09:23 PM.
  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