lundi 2 mars 2015

How to execute something only once within if-loop?

I have the following situation. I am building an experimental synthesizer interface with JavaScript. I am using the howler.js plugin to handle audio. The idea is that a sound is played if a certain condition is met. I have a number stored variable whose value chances via interaction.



if (myVariable >= 10 && myVariable <= 30) {
sound.play("myFirstSound");
}
else if (myVariable >= 31 && myVariable <= 60) {
sound.play("mySecondSound");
} else { etc etc...


The value of myVariable is changing quite often. But even if it´s constant the .play command is executed not once but over and over again causing the audio engine to run out of memory. How can I execute the commands within the if loops only once?





Aucun commentaire:

Enregistrer un commentaire