loop

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

Sign In or Register to comment.