javascript - How to cycle through an array of Audio objects -


i've started learning javascript, , i'm working on first web-embedded game, musical puzzle game uses basic principals of twelve-tone serialist music. game done, , you can find here. i'm having trouble audio. did manage play sound when user solves puzzle, can't play through notes appear on game board.

here's did: created array of 12 audio objects, contains every note c b. created method called "playtonerow()" plays through them all, order determined numeric array tonerow.notes[]. here's code:

this.playtonerow = function() {     (var in this.notes)     {         notesound[this.notes[i]].play();     } }; 

but method plays last note of tone row. should mention knowledge of javascript has been cobbled various tutorials i've found online, , i'm there significant gaps in admittedly rudimentary coding skills. figured problem wasn't putting space in between sounds, trying play them @ once, didn't have enough channels played last one. tried this:

this.playtonerow = function() {     var x = 0;     (var in this.notes)     {         x = this.notes[i];         settimeout(function()         {             notesound[x].play();         }, 700);     } }; 

now i'm not sure if i'm using settimeout() properly, i'm guessing not, because once again, played last note. know 12 wav files getting loaded, because if change tone row, play different note. have access audio files; it's matter of getting play them (and in right order).

thanks!

for won't care settimeout, try:

this.playtonerow = function() {     var x = 0,         length = 0,         j = 0;     (var in this.notes)     {         length += 1;     }      function runiteration () {         x = this.notes[j];          settimeout(function()         {             notesound[x].play();         }, 700);          if (j === length) return;          j += 1;          settimeout(runiteration, 700);      }      runiteration();  }; 

hopefully it. i've taken @ code bit complex wasn't able determine if this.notes object or array


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -