0

an array gives me different values on a single position when i print it as an array or as an element here's my code :

class tetrispiece {
  pezzo;
  elm;
  dimensioni;
  gradi;
  posizione;
  polygon = [];
//other code and the constructor (tell me if for u is relevant)
updatePolygon (x, y) {
    console.log(this.polygon, y)
    for (var i = 0; i < this.polygon.length; i++){
      console.log(this.polygon[i])
      this.polygon[i][0] += x
      console.log(this.polygon[i][1], this.polygon)
      this.polygon[i][1] += y
      console.log(this.polygon[i][1], this.polygon)
    }
  }
}
pezzoattivo = new tetrispiece(tetris.lastElementChild, pezzi[i], degrees[Math.floor(Math.random()*4)], {left : tetris.lastElementChild.getBoundingClientRect().left, top : 0});
pezzoattivo.updatePolygon(0, 1);

here's the proof : proof

  • The little 'i' icon near the object means that it has been changed since it was printed. You should find where the object is used by reference and changed – lyhoshva Mar 23 '23 at 09:57
  • @lyhoshva "*You should find where the object is used by reference and changed*" it's literally two lines after `console.log(this.polygon[i])` the code is: `this.polygon[i][1] += y` There is also a `this.polygon[i][0] += x` but I assume `x` is `0` since the log shows no change in the first element of the array. – VLAZ Mar 23 '23 at 09:59

0 Answers0