Skip to content

Please update your browser

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

Transcript

This video lets you protect your story with a secret password.

Anyone can look at your code to know this password, so it isn't very secure.

To ask for the secret password, you will use a block that allows for user input called the ask block.

From the sensing menu, place an ask block in the sprite's area.

In the white box, type the question you want the sprite to ask.

For this example the question is, "What is secret the password?"

Click on the block.

The sprite asks the question, then a box appears at the bottom of the stage.

This box is where the person watching your story will type in what they think the password is.

What they type in this box will be saved in a variable called answer.

To see what is stored in that variable, go to the sensing menu and click on the check box next to answer.

Type an answer in the box at the bottom of the stage.

You'll notice what you typed shows up in a blue box that at the top left of the stage.

Place the ask block under the when flagged click block.

Now, tell the sprite to repeat asking the password until the user gets it right.

From the control menu, place a repeat until block after the ask block.

This may put the repeat until block around your story.

Take the story out and place it under the repeat until block.

Next, program the condition that will stop the repeating when the answer is equal to the secret password.

From the operators menu, place the equals block inside the repeat until block.

From the sensing menu, place answer on one side of the equals block.

Type the secret password on the other side of the equals block.

Next, place actions that should repeat until the password is entered inside the repeat loop.

From the looks menu, place a say block inside the repeat until loop.

Make the sprite say "Nope," then ask the question again.

From the sensing menu, place an ask block after the say block.

Test the code by clicking the green flag.

The sprite asks for the password.

First get it wrong, the sprite says "Nope," then asks again.

Get it wrong again, the sprite says "Nope," and asks again.

This time, get it right.

The sprite stops asking the question and instead starts the story, perfect.

Click the stop sign to stop the story.

Try getting the answer right the first time this time.

The sprite doesn't ask for the password again, great.

But wait, the friend shows up eight seconds after the green flag is clicked regardless of the secret password.

That's because the code tells the friend to show up eight seconds after the green flag is clicked.

The wait shouldn't even start until the correct secret password has been entered.

The my sprite knows when this happens.

It can let the friend sprite know using the broadcast block.

From the events menu, place a broadcast block after the repeat until loop.

From the drop-down, select new message and give it a name that makes sense, like start story.

Next, click on the friend sprite, disconnect the wait block from the hide block.

From the events menu, place a when I receive block on the top of the wait block.

Now it's your turn.

Ask for the secret password using an ask block.

Keep asking until the password is correct using repeat until, answer, equals, ask, and say blocks.

Let the friend sprite know the story has started with a broadcast block.

And finally, detach the entire block stack after the hide block and connect it to the when I receive block on the friend sprite.

Choose an Add-On

Changing Backdrops and Costumes

Add different scenes to your story.

Changing Looks with Code

Learn what the "looks" blocks can do.

Move Around the Stage

Discover ways to make sprites move.

Animate

Animate sprites by creating new costumes.

Secret Password

Make a password to protect your story.

Instructions
  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!