WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   One slash command for two action (https://www.wowinterface.com/forums/showthread.php?t=58757)

darhanger 05-23-21 10:34 PM

One slash command for two action
 
I'm stuck with one topic, I can't implement a function like one command = two actions

Fizzlemizz 05-24-21 12:29 AM

The function for a slash commands has a single string parameter you can use for different actions:

Lua Code:
  1. SLASH_MYSLASHFUNCTION1 = "/ms"
  2. SlashCmdList.MYSLASHFUNCTION = function(msg)
  3.     local name  = UnitName("player")
  4.     if msg:upper() == "HI" then
  5.             print("Nice day to you " .. name)
  6.     elseif msg:upper() == "BYE" then
  7.             print("Time to go " .. name)
  8.         end
  9. end

Code:

/ms hi
/ms bye


darhanger 05-25-21 11:06 AM

Quote:

Originally Posted by Fizzlemizz (Post 339237)
The function for a slash commands has a single string parameter you can use for different actions:

Lua Code:
  1. SLASH_MYSLASHFUNCTION1 = "/ms"
  2. SlashCmdList.MYSLASHFUNCTION = function(msg)
  3.     local name  = UnitName("player")
  4.     if msg:upper() == "HI" then
  5.             print("Nice day to you " .. name)
  6.     elseif msg:upper() == "BYE" then
  7.             print("Time to go " .. name)
  8.         end
  9. end

Code:

/ms hi
/ms bye


what if i wanna use just /ms to turn something one and /ms to turn off? without adding worlds like /ms on or /ms off ?

Fizzlemizz 05-25-21 11:31 AM

Use a toggle depending on what you want to toggle.

Lua Code:
  1. local SomeBooleanVariable -- could be a SavedVaraible to save between sessions.
  2. SlashCmdList.MYSLASHFUNCTION = function(msg)
  3.     SomeFrame:SetShown(not SomeFrame:IsShown()) -- show/hide a frame
  4.  
  5.     SomeBooleanVariable = not SomeBooleanVariable -- toggle boolean variable
  6.     if SomeBooleanVariable then -- and action it
  7.         -- do thing if true
  8.     else
  9.         -- do thing if false
  10.     end
  11. end


All times are GMT -6. The time now is 01:33 AM.

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