Mute all sounds in game

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
hiithaard
Prole
Posts: 3
Joined: Wed Jul 01, 2020 4:49 pm

Mute all sounds in game

Post 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:
User avatar
zorg
Party member
Posts: 3444
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Mute all sounds in game

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3550
Joined: Sun Oct 18, 2015 2:58 pm

Re: Mute all sounds in game

Post by pgimeno »

Well, there's also love.audio.setVolume to set the global volume. It won't affect the individual sound volumes though.
User avatar
hiithaard
Prole
Posts: 3
Joined: Wed Jul 01, 2020 4:49 pm

Re: Mute all sounds in game

Post 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!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 244 guests