Page 1 of 1

Mute all sounds in game

Posted: Sun Jul 26, 2020 4:08 pm
by hiithaard
Hi there!

So I'm making a game where I have made a table "gSounds" which has all the sounds required.

Now, I want to add a feature which mutes all the sounds in the game.

But if I do

Code: Select all

gSounds:setVolume(0)
then it raises an error.

I can individually set the volumes of all the sounds to zero but there are so many that I have used and it'll take a lot of time in doing so. So is there any short way in which I can achieve that?

Thanks for your help! :ultrahappy:

Re: Mute all sounds in game

Posted: Sun Jul 26, 2020 4:23 pm
by zorg
You can either find a library that supports that, or you can do this:

Code: Select all

for i,v in ipairs(gSounds) do v:setVolume(0) end
assuming your table has numeric indices, otherwise you'd need to use the slower pairs iterator function instead.

Re: Mute all sounds in game

Posted: Sun Jul 26, 2020 5:07 pm
by pgimeno
Well, there's also love.audio.setVolume to set the global volume. It won't affect the individual sound volumes though.

Re: Mute all sounds in game

Posted: Sun Jul 26, 2020 5:42 pm
by hiithaard
Hey, thanks a lot guys both the methods worked! And can you tell me about the libraries that you were talking about if you know any. Thanks again!