Thread Tools Display Modes
06-29-11, 09:39 PM   #1
litesung
A Flamescale Wyrmkin
 
litesung's Avatar
Join Date: Aug 2010
Posts: 130
[Request] Macro to toggle sound

Does anyone know of a macro that will toggle sound on and off?
I want to use bindpad to bind it to a key, so that if I want to mute WoW I can just press that key, and press it again to unmute wow.
  Reply With Quote
06-29-11, 10:27 PM   #2
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Originally Posted by litesung View Post
Does anyone know of a macro that will toggle sound on and off?
I want to use bindpad to bind it to a key, so that if I want to mute WoW I can just press that key, and press it again to unmute wow.
Off:

/run SetCVar("Sound_EnableSFX", 0)


On:

/run SetCVar("Sound_EnableSFX", 1)
  Reply With Quote
06-29-11, 10:43 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
To make it into a toggle...
/run SetCVar("Sound_EnableSFX",GetCVar("Sound_EnableSFX")==0 and 1 or 0)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
06-29-11, 11:17 PM   #4
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
Oops, my bad.

Originally Posted by Seerah View Post
To make it into a toggle...
That's the ticket
  Reply With Quote
06-30-11, 06:51 PM   #5
litesung
A Flamescale Wyrmkin
 
litesung's Avatar
Join Date: Aug 2010
Posts: 130
Nibelheim always pulls through for me ty once again! TY to you too seerah!

This toggles the Sound Effects only though, so i just have to modify it to toggle sound only.

/run SetCVar("Sound_EnableAllSound",GetCVar("Sound_EnableAllSound")==0 and 1 or 0)

This is the new macro I'm using, but the problem is it only toggles sound off if it's on, and doesn't turn it back on if pressed. (stays muted)

Last edited by litesung : 06-30-11 at 06:57 PM.
  Reply With Quote
06-30-11, 08:31 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
That's because the old GetCVar() function either returns a string or nil. There are Lua functions provided in the default UI that are run by the keybind system for toggling music and sound. Using the default keybindings, you can use Ctrl+M and Ctrl+S for music and sound respectively. To do this in a macro, you make calls to Sound_ToggleMusic() and/or Sound_ToggleSound(). Both are defined in Sound.lua within the FrameXML.

Toggle Music:
Code:
/run Sound_ToggleMusic();
Toggle Sound:
Code:
/run Sound_ToggleSound();
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
07-01-11, 11:22 AM   #7
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by SDPhantom View Post
That's because the old GetCVar() function either returns a string or nil.
Why did blizzard change the old functionality?
I think the old functionality was much more useful
  Reply With Quote
07-01-11, 02:53 PM   #8
litesung
A Flamescale Wyrmkin
 
litesung's Avatar
Join Date: Aug 2010
Posts: 130
So there's no way to turn it into a toggle? It has to be done with two different macros?
  Reply With Quote
07-01-11, 03:45 PM   #9
Nibelheim
local roygbi-
 
Nibelheim's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2010
Posts: 1,600
This should work:

Code:
/run local c = "Sound_EnableAllSound"; local s = GetCVar(c) or "0"; if s == "1" then SetCVar(c, "0") else SetCVar(c, "1") end
  Reply With Quote
07-01-11, 06:59 PM   #10
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Originally Posted by Ketho View Post
Why did blizzard change the old functionality?
I think the old functionality was much more useful
GetCVar() has always acted this way. Blizzard later created GetCVarBool() that returns CVars stored as "0" and "1" as a boolean.





Originally Posted by litesung View Post
So there's no way to turn it into a toggle? It has to be done with two different macros?
See my post above:
Originally Posted by SDPhantom View Post
There are Lua functions provided in the default UI that are run by the keybind system for toggling music and sound... To do this in a macro, you make calls to Sound_ToggleMusic() and/or Sound_ToggleSound(). Both are defined in Sound.lua within the FrameXML.

Toggle Music:
Code:
/run Sound_ToggleMusic();
Toggle Sound:
Code:
/run Sound_ToggleSound();
Note: These are two different commands, you can put them together in a single macro if you wish.
Code:
/run Sound_ToggleMusic();
/run Sound_ToggleSound();
or more efficiently...
Code:
/run Sound_ToggleMusic();Sound_ToggleSound();
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 07-01-11 at 07:04 PM.
  Reply With Quote
07-02-11, 08:30 AM   #11
Ketho
A Pyroguard Emberseer
 
Ketho's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,026
Originally Posted by SDPhantom View Post
GetCVar() has always acted this way. Blizzard later created GetCVarBool() that returns CVars stored as "0" and "1" as a boolean.
If I remember correctly, GetCVar used to return "0" instead of just a nil, breaking the following example ..
Code:
/run SetCVar("Sound_EnableSFX", 1-GetCVar("Sound_EnableSFX"))
I can remember that the above example script used to work, but not anymore now
  Reply With Quote
07-02-11, 08:36 AM   #12
litesung
A Flamescale Wyrmkin
 
litesung's Avatar
Join Date: Aug 2010
Posts: 130
Originally Posted by Nibelheim View Post
This should work:

Code:
/run local c = "Sound_EnableAllSound"; local s = GetCVar(c) or "0"; if s == "1" then SetCVar(c, "0") else SetCVar(c, "1") end
Originally Posted by SDPhantom View Post
or more efficiently...
Code:
/run Sound_ToggleMusic();Sound_ToggleSound();
These two work perfectly

I tried them both, Nib's is silent (no notification), and Phantom's notifies you "Sound Effects Enabled/Disabled" message.

THANK YOU EVERYONE! Hopefully no future patches break these.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » Macro Help » [Request] Macro to toggle sound

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