So in class, I have to do a text based game in HSA console. It's been alright except for one error. When the user inputs something the program doesn't understand, I want it to print "That command is not recognized" and reprint the part of story they were at before instead of going back to the beginning to start over again. I've done it by assigning a value to a variable under every different part of the story. But now when I try to break back to the part of the code, it says that some of the things are an undeclared variable.
This is my code for this particular section:
hallway: if (key_entered == 'S' || key_entered == 's') { c.print ("\n\nYou are standing in a dark hallway. There is a door to the north, and a light coming from the west. "); error = 1; directionHallway = c.readString (); door: if (directionHallway.equals ("north")) { c.print ("You approach the door and stare at it. A while passes."); c.print ("\nAnd then you realize it's locked. There's a keyhole on the door. "); error = 2; directionDoor = c.readLine (); if (directionDoor.equals ("open door") && (key = false)) { c.print ("It's locked."); } else if (directionDoor.equals ("open door") && (key = true)) { c.print ("The door slowly creaks open and you enter."); } } blankwall: if (directionHallway.equals ("east")) { c.print ("There is simply a blank wall to the east. Nothing to do but backtrack to where you were. "); error = 3; directionBlankWall = c.readLine (); } haggis: if (directionHallway.equals ("south")) { c.print ("There is a wall that is devoid of anything but a poster. It simply says 'Haggis'. "); error = 4; directionHaggis = c.readLine (); } statueroom: if (directionHallway.equals ("west")) { c.print ("The light leads to a room with a strange statue."); c.print ("\nThere are doors to the north, west, and south. "); error = 5; directionStatueRoom = c.readLine (); } else { c.print ("That command is not recognized."); if (error == 1) { break hallway; } if (error == 2) { break door; } if (error == 3) { break blankwall; } if (error == 4) { break haggis; } if (error == 5) { break statueroom; } } }
The only ones that are being highlighted as undeclared labels are the door, blankwall, and haggis. Anyone know what's wrong? And yeah, I'm a total beginner at this.