0
\$\begingroup\$

I have the following in my update funtion. The first input for key_enter when textPos!=2 works fine, but the one when textPos==2 doesn't work. The key up and down work fine though.

The System.out.println("Enter: " + choice); never gets printed

public void update() {
        Input input = gc.getInput();
        if (input.isKeyPressed(Input.KEY_ENTER)) {
            if (textShowing && textPos != 2) {
                textPos++;
                textShowing = false;
            }
        }
        if (textShowing && textPos == 2) {
            if (input.isKeyPressed(Input.KEY_ENTER)) {
                System.out.println("Enter: " + choice);
                if (choice == 0) {

                } else if (choice == 1) {

                } else {
                    textPos++;
                    textShowing = false;
                    System.out.println("Text Pos: " + textPos);
                }
            } else if (input.isKeyPressed(Input.KEY_UP)) {
                if (choice > 0) {
                    choice--;
                }
            } else if (input.isKeyPressed(Input.KEY_DOWN)) {
                if (choice < 2) {
                    choice++;
                }
            }
        }
    }
\$\endgroup\$
  • \$\begingroup\$ Have you tried attaching the debugger? Set a break point, check your variable values. Pay special attention to textShowing and the value of textPos. \$\endgroup\$ – MichaelHouse Apr 25 '14 at 15:57
  • \$\begingroup\$ Figured it out. If i switch the "if (input.isKeyPressed(Input.KEY_ENTER))" and "if (textShowing && textPos != 2) {" the other way around it works \$\endgroup\$ – Ceri Turner Apr 25 '14 at 16:03
  • \$\begingroup\$ You might want to enter that as an answer to this post, and mark it answered :) \$\endgroup\$ – Dylan Meeus Apr 26 '14 at 8:07
  • \$\begingroup\$ Wouldn't let me answer it yesterday as I didn't have enough rep \$\endgroup\$ – Ceri Turner Apr 26 '14 at 9:47
0
\$\begingroup\$

Figured it out. If i switch the "if (input.isKeyPressed(Input.KEY_ENTER))" and "if (textShowing && textPos != 2) {" the other way around it works

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.