Help with for()

Hello!
I am working in a minigame based in StarCastle(Vectrex), and i am trying to draw the shields:

void drawLines(){ 
    for(ArrayList<PVector> line : this.shield){
      switch(this.shield.indexOf(line)){
        case 0: stroke(255,0,0); break;
        case 1: stroke(255,255,0); break;
        case 2: stroke(0,255,0); break;
      }
      for(PVector miniShield : line){
        int iMiniShield = line.indexOf(miniShield);
        if(iMiniShield>0){
          PVector LastMiniShield = line.get(iMiniShield-1);
          strokeWeight(3-line.get(iMiniShield).z);
          if(line.get(iMiniShield).z>0)
            line(miniEscudo.x, miniEscudo.y, miniEscudoAnterior.x, miniEscudoAnterior.y);
        }
      }
    }
  }

this.Shield is an ArrayList that has 3 ArrayLists with 8 PVectors.

My problem is that I always get 0 when I use.indexOf(), what am I doing wrong?

First, you need to provide more code. For instance, where is the the definition of your line object? Also, consider changing this name as line is a reserved word for the line() function.

Also, format your code properly before you posted here. In the PDE, press ctrl+t. Here, for a doe block, enclose your code in a pair of triple back ticks.

Kf

1 Like

Well, I solved the problem using for(init; test; update) instead for(datatype element : array), the problem was that array.indexOf(element) inside for(datatype element : array) was always getting 0.

1 Like