{% trans 'Watch it here now.' as msg_meta_extra} What's the Password? - Interactive Storytelling - CS First 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 What's the Password?

Transcript

This addon uses a new concept, repeat until, and is more challenging than some of the others.

At the end of this addon, the user will need to give the character the correct password in order to go through the secret door.

As the programmer, you will get to choose the password.

First, you will need to ask for the password.

To do this, use the same block you used to ask if the character should go through the secret door, which is the ask block.

Type a question in the ask block.

This example says apparently to go through the door I need a password.

What is the password?

This addon is different from should I go through the secret door in the core project.

In this addon, if the user doesn't get the password right the program will keep prompting for a password.

To keep doing something over and over you need to use a loop.

The repeat until loop, for example, allows something to keep happening until a condition is met.

From the control menu drag out a repeat until loop.

Place it below the ask block.

Start by filling out the condition.

In the core project the condition was answer equals yes.

The condition for this addon is very similar.

Check if answer equals the correct password.

This example uses the password scratch, so the condition reads answer equals scratch.

Now, program what should happen until the condition is met.

For this addon, the program should keep asking for a password until the user enters a correct one.

To ask for the password again, put the ask block inside the repeat until loop.

Make the ask block say something that will help the user understand what happened.

This example says that was not correct, what else could it be?

Make sure that the user can enter a new answer somewhere or they will be stuck inside the loop forever.

By doing this, you'll make sure to give the user a chance to enter the correct password.

Click on this code to test it.

The character asks for the password.

Now to make sure the repeat until loop works, first type an incorrect answer.

This example will enter cat.

Since the condition answer equals scratch was not met, the code inside the repeat loop will execute.

For this example the code asks that was not correct, what else could it be?

Try one more incorrect test just to see what happens.

This example types dog.

The code inside the repeat loop should run again.

This time answer correctly.

In this example the correct password, scratch, is entered so the repeat loop stops running and the story continues.

Now we need to put this code where it belongs in the code you already created.

If you would like your story to wait to start until the correct password is entered, place the code you just created right under the green flag.

You could also instruct the program to ask for the password before the character goes through the secret door or at another point in the story that makes sense to you.

This example asks for the password when the user has already decided to go through the door.

So, it runs after the then portion of the if answer equals yes block.

Test your code by clicking on the green flag.

The program should only continue after you've entered the right password.

Finally, you can add a say block that lets the user know the password was correct.

Now it's your turn.

First, program the condition for the answer equals correct password condition.

Second, put the condition in a repeat until block.

Third, put something else inside the repeat until block that should keep happening until the user enters the correct password.

Make sure you use the ask lock, both inside and before the loop.

And then, put this whole structure inside your code where it makes sense.

Choose an Add-On
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.
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
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!