LWJGL state flicking back and forth

Hi,

I am trying to use these options to switch from the Menu to Options, however, on the first time I press it, it flicks to options and back again really quick, but after that it works fine?

	private void select() {
		if(currentChoice == 0) {
		Game.state = State.RAND;
		}
		else if(currentChoice == 1) {
		Game.state = State.OPTIONS;
		}
		else if(currentChoice == 2) {
			Display.destroy();
			System.exit(0);
			AL.destroy();
		}
	}

	private boolean wasDown = false;
	private boolean wasUp = false;
	private boolean wasEnter = false;
	
   public void handleInput() {   
	   //checks if the key is down and executes once
		boolean up = Keyboard.isKeyDown(Keyboard.KEY_UP);

		if (!wasUp && up) {
			if(currentChoice > 0) {
				currentChoice--;
			}
		}
		wasUp = up;
	   
	   
	   //checks if the key is down and executes once
		boolean down = Keyboard.isKeyDown(Keyboard.KEY_DOWN);

		if (!wasDown && down) {
			if(currentChoice < options.length - 1) {
				currentChoice++;
			}	
		}
		wasDown = down;
		boolean enter = Keyboard.isKeyDown(Keyboard.KEY_RETURN);
			if (!wasEnter && enter) {
			select();
		}
		wasEnter = enter;
     }

Any ideas why this might be happening?
Thanks,

  • Dan
   if (!wasDown && down) {
         if(currentChoice < options.length - 1) {
            currentChoice++;
         }   
      }

This bit looks weird to me, probably not the cause but why length of array -1?

Seems you are using index 0-2 so don’t see the need to put -1 in, out of bounds is not possible due to your checks

You need to do more Object Oriented programming instead of “Linear” or how should this be called.