Is this a reasonable sound system?

L

Lok_OS

Guest
Hello. I've programmed a settings menu which lets you, among other things, toggle the sound effects and music on/off.
The easiest way I found to do that was to have it unload/load the separate audio-groups that I had created for music and sounds. This way, instead of putting
and "if" statement at the start of ever audio_play, the sound will just not play if the audio group is unloaded.

My question is, is this a good way to do it? Will there be any long term repercussions?
I noticed that in the Compile, every time it tries to play a sound that's unloaded, it will display a "Audio Group is not loaded" message, now seeing how
this is not your typical error message that shows up in the game window it doesn't seem to matter? Maybe?
What are the negative side effects of this, if any? Will this be something that negatively affects how the game runs or will it work fine?

Thanks.
 

Nidoking

Member
I set the gain for the audio groups to zero and keep them loaded or unloaded as they should be. I don't like relying on safety nets and intentionally provoking errors as a means of flow control.
 
L

Lok_OS

Guest
I set the gain for the audio groups to zero and keep them loaded or unloaded as they should be. I don't like relying on safety nets and intentionally provoking errors as a means of flow control.
Oh that sounds like a much better alternative, how silly I didn't think of that before.
Thanks a bunch.
 

FrostyCat

Redemption Seeker
This is awful technique. Reliance on undocumented forgiveness is never a good way to do anything.

The proper technique is to hide the configuration check behind a script, like this:
GML:
///@func sfx_play(sound, priority, loop)
///@param sound
///@param loop
return global.sfx_on ? audio_play_sound(argument0, argument1, argument2) : noone;
Then you can do a global search-and-replace everywhere else, and the configuration check would be embedded into every attempt to play a sound.

This can be combined with your audio group unloading to reduce memory usage, but in any case, it is improper form to attempt using an unloaded resource.
 
Last edited:

obscene

Member
Just adding, seems keeping the audio groups loaded would be best so you don't have to cause the game to freeze to reload them if someone is just muting the sound for a moment. I would think 99.9% of gamers play with the sound on anyway. If anything, you just want to make sure you give them some nice sliders to balance sound effects, ambience and music.
 

kburkhart84

Firehammer Games
This is one of those times where I suggest you not rely on undocumented behavior. Right now, its working fine...later on, they may change something and give an error if you do it.
 
Top