Help with for()

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){
        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);
          PVector LastMiniShield = line.get(iMiniShield-1);
            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.


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