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.
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 enterPasscode function. At the top, we start a text string asking for the password.
Add to the string so it's something like this.
Now we have to check for an empty string and then skip the penalty. Go to the checkPassword function.
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.
When the player clicks on the Try Passcode button with a blank entry, this will clear off the passcode interface and put the player back into the current room without any penalty. If you're happy with that, then you're done!
If you want to tell the player they walked away from the passcode panel, then you'll need to make a button like the
penalty button. Instead of the moveToRoom();
line above, replace it with
something like this.
And that's it. Feature updated!
We have to make edits to two functions to get this to work. But they're pretty minor.
Go to the getPasscodeHint function we created for offering hints. We have two options for fixing the text. We can put the explanation at the top of the text block or at the bottom.
At the very top of the function, we start an empty text string. Just add the information there.
We still need to check to see if the player left the passcode blank. That part's the same as above in the section
without the hints.
Jump up to step 2 in the previous section.
To put the explanation at the bottom, you have to change the places where we ask for the passcode and put the explanation there. We have one at the top of the getPasscodeHint function inside the check for a penalty and inside the code block where the player does not have enough points for a hint.
There's only one line to add here...
And at the bottom of the function...
We still need to check to see if the player left the passcode blank. That part's the same as above in the section
without the hints.
Jump up to step 2 in the previous section.