Quantcast
One slash command for two action - WoWInterface
Thread Tools Display Modes
05-23-21, 10:34 PM   #1
darhanger
A Deviate Faerie Dragon
 
darhanger's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2017
Posts: 10
One slash command for two action

I'm stuck with one topic, I can't implement a function like one command = two actions
  Reply With Quote
05-24-21, 12:29 AM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,429
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-24-21 at 02:30 AM.
  Reply With Quote
05-25-21, 11:06 AM   #3
darhanger
A Deviate Faerie Dragon
 
darhanger's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2017
Posts: 10
Originally Posted by Fizzlemizz View Post
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 ?
  Reply With Quote
05-25-21, 11:31 AM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,429
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
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 05-25-21 at 11:33 AM.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » One slash command for two action

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