When the player is asked to enter the passcode, they may not know what to enter, or they may know they're not ready to. In this case, the player would want to exit out without even trying to enter anything.
Right now, our game gives the player a penalty for leaving the passcode screen for any reason unless they gave a correct answer. Let's fix this so the player can walk away if they want to without losing points.
There's one last thing to consider. What if the player accidentally went to the passcode panel? What if they want to leave it without trying to punch anything in? As we are right now, they get a penalty for not having a correct passcode. An empty passcode is considered incorrect, so they get a penalty.
Do you want to allow the player to walk away from the passcode panel without a penalty? If so, we have to fix something.
Scroll to the section that best fits your code.
First, we should tell the player they have the option of walking away.
Go to your moveToRoom function and look for the line that has a prompt asking for the password.
Update the string to something like this.
Now we have to check for an empty string and then skip the penalty. You should still be inside the moveToRoom function where we just updated the passcode string.
We have an if check to see if the player got the passcode correct. If not, they immediately lose points in the following else block. You know what we need to do, right?
We need to insert an else if check for the empty string.
And that's it. Feature updated!
We have to make edits to two functions to get this to work. But they're pretty minor.
In the getPasscodeGuess function we created for offering hints, we have a section that creates a text string that asks for the passcode. This is where we need to make a change.
Find the first line below and then add the second one.
Now we have to check for an empty string and then skip the penalty. This takes place inside the moveToRoom function. This change is exactly the same as the text version above without the hint feature.
We have an if check to see if the player got the passcode correct. If not, they immediately lose points in the following else block. You know what we need to do, right?
We need to insert an else if check for the empty string.
And that's it. Feature updated!