Is it possible to add 2 sounds simultaneously?

Hi everyone.

I know this option is not available, I understand that you can only add audio files with the *sound command.

I would like to know if someone knows a method, either by using *if, to be able to reproduce 2 sounds at once.

The idea would be to play only 2 files at a time, since I would like to live a scene with music plus the natural environment.

Example:

He walked and walked through the forest. His thoughts torment him at every step, trapping him in a sea of ​​grief.
The night looms over the tall treetops, which seem to draw strange silhouettes in the dim moonlight.

That was a simple example. Now, imagine it with music and forest fan.
That is what I would like to do, although I think it is not possible.
But, maybe you can play with the *sound command and the *if commands.
If anyone knows any way in which this could be possible, even if it is not recommended, I would appreciate it if you could tell me how you could get it.
Regards!.

Your code can execute both *sound and *if command “simultaneously,” one by one. However, any new *sound lines will override the old ones.

*sound music.ogg
*if forest
   *sound forest.ogg
   Welcome to the forest.
*elseif beach
   *sound beach.ogg
   You're now on the beach.

The music will start playing out first, but once the code resolves either *if, the music will stop and will be playing the ambient sound instead.

3 Likes

Woah! I had no idea that CS had any sound commands. Are there any published games or WIP that have implemented this yet?

1 Like

I think there’s a few that do. Can’t recall them off the top of my head. I do remember one mech sci-fi game that used sounds in its battle system.

1 Like

I don’t believe u can, but I may be wrong. U can however use Audacity to put those 2 files together and make them 1 to use that instead.

2 Likes

Think it that way - you can’t play two files at the same time with any audio player.

Hello guys. Thanks to everyone for your replies.
Now I have another big question, to have who gives me a hand.

I am reading and learning about javascrypt, and I would like to get something that I think could be useful for those of us who want to include sounds in our games.
I have read of an event to preload all the audio files in the cache and be able to play them without delay.
My problem is that I know how to apply it correctly in the playSound function
I leave the function dedicated to the sound that includes CS, and the event, who can help me.

PlaySound function:

code:
function playSound(source) {
for (var existingAudios = document.getElementsByTagName(“audio”); existingAudios.length;) {
existingAudios[0].parentNode.removeChild(existingAudios[0]);
}
if (typeof hashes != ‘undefined’ && hashes[source]) {
source += “?hash=” + hashes[source];
}
var audio = document.createElement(“audio”);
if (audio.play) {
audio.setAttribute(“src”, source);
document.body.appendChild(audio);
audio.play();
}
}

Event to preload the files before playing them:
code:
audio.addEventListener(‘canplaythrough’,function(){