Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Find the Secret Door


This add-on is slightly more challenging than some of the others. After program this add-on, the user will be able to control the movements of the main character. Also, the main character will only notice the secret door once it touches it.

First, program the character to move with the arrow keys.

Drag out a “move 10 steps” block, and click on it.

The character will probably move right.

Place a “when key pressed” event above the “move 10 steps” block, click the dropdown, and select “right arrow.” Test this. Press the right-arrow key. The character should move right. Great. Now, create similar code to make the character move left. Right click on the code to move right, and click “duplicate.” Change the dropdown to “when left arrow clicked.” Negative numbers in Scratch do the opposite of positive numbers. If “move 10 steps” moves a sprite right, “move negative 10 steps” moves it left. Add a negative sign in front of the 10 in “move 10 steps” to code for the left-arrow key. Test your code. Pressing the left arrow should move the sprite left, and pressing the right arrow should move the sprite right.

This is a basic way to make characters move. If you’d like more information about how to make it look like sprites are actually walking, watch the add-on “Walking.” Instead of putting the walking code inside an “if-else” statement, put it under the appropriate events.

Next, make sure the sprite starts in the same spot each time the story is told, regardless of where it gets moved during the story. To do this, move the character to where it will start. Then, place the “go to x y” block just under the “when green flag is clicked” block. Now the main character walks, but it still immediately mentions the secret door, rather than waiting until it is touching the door to notice it. To make your program wait for a condition, use the “wait until” block. First, fill out the condition.

The sprite can see the door when it is touching it.

The door is part of the background, however, it is the only part that is black. The character can tell it is touching the door if it is touching the color black.

Drag the “touching color” condition into the “wait until” block.

Next, make sure the color in the condition matches the color of the door. Click on the color, then click on the door. Now the block should read “wait until touching color black.”

Figure out where to place the “wait until” block.

Watch what happens when the “wait until” block is placed immediately after the “when green flag is clicked” block. The character doesn’t reset its position, and the scene doesn’t reset to the brick wall!

That happened because when the green flag is clicked, the program waits until the character is touching black before doing anything else. Instead, try moving the wait block after all the set-up, placing it before “should I go through the secret door?”

Test the code. The character begins in its starting position, and the background starts as the brick wall. Move the character. As soon as it touches the black door, it asks if it should go through it. Great. Next, tell the user how to make your program work using the right and left arrow keys. To do this, add a “say” block after the “go to” block. In this example, the character goes to its starting position, then says, "Use the arrow keys to make me move!”

Then, once it touches the black door, it asks the user if it should go through the door. Computer scientists rarely program what they want correctly the first time. They have to be persistent and keep trying until they solve the problem. When you keep working at a problem to figure out how to fix it rather than giving up, you are acting like a computer scientist! Now, it’s your turn: Use the “move” and “when key pressed” event blocks to make the character move when the arrow keys are pressed. Use the “wait until” block to make the character wait until it touches the door before asking if it should go through it.

Make the condition in the “wait until” block “touching color black.”

Tell the user to press the arrow keys to move your sprite by adding a “say” block after the “go to” block.

Choose an Add-On
In this video, you’ll learn how to make it look like the character is walking towards or away from the door.
What's the Password?
In this add-on, you'll program a secret password that the user must enter to travel through the secret door.
Make it Rain
In this add-on, you'll learn how to use the backpack to add the rain from your day 3 project into this project.
Find the Secret Door
In this add-on, you'll program the main character so the audience can use the arrow keys to find the secret door.
Add Another Character
In this add-on, you'll add more characters to your story.
Add Another Scene
In this add-on, you'll be prompted to add another scene, and given some ideas about how to program it.
arrow_backward Back
Next arrow_forward
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!