Is it possible to preload all audio files when the game is online?

I’m having trouble with…

The error I’m getting is:…

My code looks like this:

Example
*commend
    Indent
```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(){

It is possible to preload assets, I’d suggest googling for how to do that with JavaScript. Someone is likely to have already written something like that you can copy/paste - when doing so check they released the code under a license that allows you to use it commercially such as MIT or BSD.

Hi @fgillusi! This category is for solving issues related to Choicescript, not Javascript. COG doesn’t officially support any custom Javascript code and most users here aren’t familiar with it, so you might have more luck finding help through Google.

As far as I know, audio files are treated like image files in that they’re loaded to the device the user is playing on when they launch the game, so there’s no need to preload them using custom code.

1 Like