We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a code which purpose is to initialise rectangle upon a canvas. Unfortunately I have an error because my "i" is out of range : "undefined is not an object (evaluating 'this.Tableautemp[i].w')". I cannot stop the while loop before "I" is out of array range. I try with an if clauses like this but it did not work. My if clause is look like :
if (typeof Tableautemp[i] !=== 'undefined') { then do the while loop's of the code bellow }
Do you have any clue?
Here is the code (everything else is fine and the parameters of the array exists and have been updated in the setup.)
function PositionObjets (Tableautemp) {
this.Tableautemp = [];
this.Tableautemp = Tableautemp;
this.Tableaureste = Tableautemp;
fill(0);
stroke(250);
let x =xinit;
let y =yinit;
let spacing = 0;
let i = 0;
while (y+margeh<=htot) {
console.log(i);
while (x+this.Tableautemp[i].w+margew<=wtot) {
this.Tableautemp[i].x = x;
this.Tableautemp[i].y = y;
this.Tableautemp[i].Move();
this.Tableautemp[i].Dessine();
x=x+this.Tableautemp[i].w+spacing;
i=i+1;
this.Tableaureste = this.Tableaureste.splice(0,1);
}
x=xinit;
y=y+hp;
}
if (i<this.Tableautemp.length-2) {
// i=i+1;
}
}
Answers
Uh... Use a for loop?
This loop will allow you to do the same things to each object in your Tableautemp array.
@tfguy44 thanks But as I did not know the length (in pixel) of my items they probably quit the canvas. I will try with your suggestion.
@gotoloop thank you for the information ! :))