Sound on a channel

The action “sound on a channel” just play one sound at a time how can I use it for my game to play all the sound effects properly and control their volume globally?

The action to play a sound (no sound channel) can play multiple sounds at once, I think, but you can’t manage them (stop this one, pause this other).

Sounds channel:
If you want to use channels, you’ll have to manage multiple channels to get multiple sounds playing at the same time, for example you could track the last channel used in a variable, and increase it each time you play a sound, this way each sound will be played in a different channel.

Sounds global volume:
To get a “Global sound volume” for all the channels, guess it… yes, a variable, and use this variable in every sound playing action :slight_smile:

In summary, using the two variables previously explained, you could do it:

[code]Conditions: At the beginning of the scene
Actions: Do = 0 to variable Current_Channel
Do = 50 to global variable Sound_Volume

Conditions: Conditions to change global sound volume
Actions: Do = X to global variable Sound_Volume

Conditions: Conditions to play a sound
Actions: Play sound MySound.wav, channel = Variable(Current_Channel), volume = GlobalVariable(Sound_Volume)
Do + 1 to variable Current_Channel[/code]

I don’t know if there is a limit in the channels number, anyway it could be a good idea to limit the number of active channels, in case GD doesn’t manage inactive channels properly, for performance reasons. I would modify the last event to get, for example, 14 active channels:

Conditions: Conditions to play a sound Actions: Play sound MySound.wav, channel = Variable(Current_Channel), volume = Variable(Sound_Volume) Do + 1 to variable Current_Channel // Sub event Conditions: Variable Current_Channel >= 14 Actions: Do = 0 to variable Current_Channel
Another version with the same effect (notice the “mod” function) :nerd:

Conditions: Conditions to play a sound Actions: Play sound MySound.wav, channel = mod(Variable(Current_Channel), 14), volume = Variable(Sound_Volume) Do + 1 to variable Current_Channel

Actually I guessed it a few days ago, that I need a sfx global variable for this, So why need a sound channel anyway!

Are you asking me something?, sorry, no perfect english here :stuck_out_tongue: