Mute button

Hi,

How could I make a mute button which let’s me turn the sound back on by clicking it again (it would also be nice if the image would switch when the button is pressed).

Here is my code at current:

  
-- Load Background Music 1  
  
media.playSound( 'music1.mp3', true )  
  
-- Music Pause Button  
  
local musicbutton = display.newImage( "musicnote1.png" )  
 musicbutton.x = 965  
 musicbutton.y = 705  
  
function musicbutton:tap( event )  
 media.pauseSound( 'music1.mp3' )  
  
end  
  
musicbutton:addEventListener( 'tap', musicbutton )  
  

Best Regards,

Adam. [import]uid: 83162 topic_id: 13786 reply_id: 313786[/import]

*By switch I mean that when the music is muted it swaps to an image of a music note with a red line through it until tapped again (and un-muted). [import]uid: 83162 topic_id: 13786 reply_id: 50615[/import]

use some variable like soundIsMute = false and change it to = true then you click on icon
then check if variable is true and with that do another thing in your function…
i hope i explained it simple enough) [import]uid: 16142 topic_id: 13786 reply_id: 50616[/import]

I tried:

  
-- Load Background Music 1  
  
media.playSound( 'music1.mp3', true )  
  
local SoundPlaying = true  
  
local SoundMute = false  
  
-- Music Pause Button  
  
local musicbutton = display.newImage( "musicnote1.png" )  
 musicbutton.x = 965  
 musicbutton.y = 705  
  
function musicbutton:tap( event )  
 if SoundPlaying = true then  
 media.pauseSound( 'music1.mp3' )  
 SoundPlaying = false  
 SoundMute = true  
 else  
 media.playSound( 'music1.mp3', true )  
 SoundPlaying = true  
 SoundMute = false  
end  
  
musicbutton:addEventListener( 'tap', musicbutton )  
  

But am getting a syntax error saying that a “then” is expected near the “=” sign…

I may just be making a noobs mistake XD (haven’t been coding much in a while other than in html and css). [import]uid: 83162 topic_id: 13786 reply_id: 50627[/import]

in “if” statements you need to use ==, not single = [import]uid: 16142 topic_id: 13786 reply_id: 50637[/import]

lol, thanks darkconsoles. That fixed it ^^ [import]uid: 83162 topic_id: 13786 reply_id: 50652[/import]