I have the following code in my update function, which is called 30 times per second:
// Checking collision between rune and the players:
for(var j = 0; j < this.players.length; j++) {
if(this.checkCollision(this.players[j], this.runes[i])) {
this.runes[i].activate(this.players[j]);
this.runes[i].isHidden = true;
this.runes[i].onDeactivate = function() {
console.log(i);
self.runes.splice(i, 1);
}
}
}
before that I have:
for(var i = 0; i < this.runes.length; i++) ...
the self.runes.splice(i, 1) does nothing to an array... i is being set to some value. I just want to remove the not active rune from array of runes. Any Ideas?
console.log(i)show you?self.runes.splice(i, 1)in an asynchronous function. By the time it runs,iwill be outside the length of the array.