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 alert to tell the player they can walk away.
  • Add a check for a blank passcode entry and skip the penalty.

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.

Text 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 moveToRoom function and look for the line that has a prompt asking for the password.

Update the string to 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. 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!

Text 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

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.

Step 2: Checking for a blank passcode entry

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!

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

—Dr. Wolf