I'am trying to play sounds respectively using setTimeout
. I have an array called challenge
which has (for test purposes) [0,1,2,3]
and also a function which is play(n, true)
for starting the sound and play(n, false)
for stopping the sound. What I'am trying to do is:
play(0, true)
.wait1seconds.play(0,false)
.wait1secondsplay(1, true)
.wait1seconds.play(1,false)
.wait1seconds and so long.
What I have written so far is:
watch: {
turn: function(turn) {
if (this.turn === 0) {
var self = this;
var time = 500;
var timeArray = [[],[]]; // I tried with and without this array
for (var i = 0; i < this.challenge.length; i ++) {
timeArray[0][i] = setTimeout(function() {
self.play(i, true);
}, time);
timeArray[1][i] = setTimeout(function() {
self.play(i, false);
this.time += 1500; // // I tried with and without this
}, time + 1000);
}
}
}
}
Without the array, I just play everything at once and occasionally making a sound which I am able to detect. With the array it's just object error.