Please help!! Putting Array into an If Statement?

edited April 2015 in Programming Questions

I'm making a simple game where a bunch of objects in an array appear at the same time. Pressing the mouse will remove the array of objects in a class (sample code below). When it hits 0 want it to head into another game State.


void mousePressed() {
  
    if (gameState == RUN_GAME) {
    objects.remove(0);
  }
}

When it hits 0 and theres no more objects in the sketch and you mouse press, processing automatically freezes. I've tried something like this (below) but it obviously doesn't work. How could I tell the if statement to change the gameState once the array list of objects hit 0? I hope I'm making sense.


void runGame(){
  
    if (objects.length == 0) {
    gameState == WINNER);
  }
}

Answers

  • void mousePressed() {
       if (gameState == RUN_GAME) {
            if (objects.length>0)
                objects.remove(0);
      }
    }
    
  • gameState == WINNER);
    has syntax errors. It should be:
    gameState = WINNER;

Sign In or Register to comment.