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=53285)

suipsyco 04-02-16 06:55 PM

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."

Dridzt 04-02-16 07:48 PM

Quote:

Originally Posted by suipsyco (Post 313937)
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.

suipsyco 04-02-16 08:29 PM

Thanks that worked! So am I to understand that SlashCmdList[""] need to be a function then?

Fizzlemizz 04-02-16 08:57 PM

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.

suipsyco 04-02-16 09:04 PM

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");


Fizzlemizz 04-02-16 09:28 PM

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.

suipsyco 04-02-16 09:44 PM

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

Fizzlemizz 04-02-16 09:48 PM

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.

Uitat 04-03-16 08:21 PM

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


MunkDev 04-03-16 09:07 PM

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

Uitat 04-03-16 09:17 PM

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



All times are GMT -6. The time now is 03:36 PM.

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