The Room Adventure: Additional Features

Leave passcode entry without a penalty

Difficulty: ★☆☆☆☆

Requirement: Passcode Ending

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 we need to do

  • Update the passcode screen to tell the player they can walk away.
  • Add a check for a blank passcode entry and skip the penalty.

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.


HTML version: Without the passcode hints

First, we should tell the player they have the option of walking away.

Step 1: Telling the player

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.

Step 2: Checking for a blank passcode entry

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.

Option 1: Don't tell the player they walked away

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!

Option 2: Tell the player they walked away

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!


HTML version: With the passcode hints

We have to make edits to two functions to get this to work. But they're pretty minor.

Step 1: Telling the player

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.

Easy fix: Explanation at the top

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.

Longer fix: Explanation at the bottom

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.

Now you can leave... er, wait! Don't go!

—Dr. Wolf