Help: Sound/Music Enable and Disable

Hello guys,

I don’t know if somebody has ask this already, I kept on searching on the forums but I can’t find anything,

my question is how can I make the Sound/Music of my app dynamic? (I don’t know the correct term to use) Like when the player wants to disable the sounds when he/she taps a button, or the disable the background music when they got bored listening to it.

Thanks in advance,

Jam

The way I do it is I have a flag like:

local mySettings = {}

mySettings.soundOn = true

then if they tap a button to turn off sound, I change the flag to false:

mySettings.soundOn = false

Then every where I play a sound I wrap it in an “if” statement:

if mySettings.soundOn then

    audio.play(mysound)

end

Now I put the setting in a table of all my settings for easy saving/loading of the settings data between sessions. You can also do things like:

mySettings.musicOn = true

and use the same thing to separate your background music from your sound effects.

Thank you very much Bob! that solves my problem :slight_smile:

@Jam Paraiso: A simpler way to do this might be to just set the volume for your app (or a specific channel, such as one for music) to 0. One tap sets the volume to 0 (and sets a flag similar to what Rob Miracle indicated). The next tap checks the flag, and if the sound is off, restores the volume to the normal level. This way you won’t need to surround each sound effect with if statements.

The way I do it is I have a flag like:

local mySettings = {}

mySettings.soundOn = true

then if they tap a button to turn off sound, I change the flag to false:

mySettings.soundOn = false

Then every where I play a sound I wrap it in an “if” statement:

if mySettings.soundOn then

    audio.play(mysound)

end

Now I put the setting in a table of all my settings for easy saving/loading of the settings data between sessions. You can also do things like:

mySettings.musicOn = true

and use the same thing to separate your background music from your sound effects.

Thank you very much Bob! that solves my problem :slight_smile:

@Jam Paraiso: A simpler way to do this might be to just set the volume for your app (or a specific channel, such as one for music) to 0. One tap sets the volume to 0 (and sets a flag similar to what Rob Miracle indicated). The next tap checks the flag, and if the sound is off, restores the volume to the normal level. This way you won’t need to surround each sound effect with if statements.