Hello!
I'm having some issues with a switch, or at least I think it's the switch...
Theoretically, after the switch receives a "YES", it should change the state String to "EXPLORE", thus ending the whole chain. But that's not what's happening.Code:// STATE is a String, command is a JTextField
// This is all inside of an ActionListener, so nothing happens until it gets input.
if (STATE.equals("CREATECHAR")){
String name = command.getText();
display.append("\nAre you sure you want your name to be " + command.getText() + "?");
switch (event.getActionCommand().toUpperCase()){
case "YES": case "Y":
player.setName(name);
display.append("\nWelcome to Generica, " + player.getName() + "!");
STATE = "EXPLORE";
break;
case "NO": case "N":
display.append("Well what is your name, then?");
break;
}
}
Output is:
What is your name, Adventurer?
Are you sure you want your name to be John?
Are you sure you want your name to be Yes?
Welcome to Generica, Yes!
Any idea why I'm getting the odd looping?
Thanks in advance!
