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 Qual è la password?

Transcript

This add-on uses a new concept, “repeat until,” and is more challenging than some of the others.

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, 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 add-on is different from “should I go through the secret door?” in the core project. In this add-on, if the user doesn’t get the password right, the program will keep asking for a password. To keep doing something over and over, 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 = yes.” The condition for this add-on is very similar: This example uses the password “scratch,” so the condition reads “answer = scratch.”

For this add-on, the program should keep asking for a password until the user enters the 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 wasn’t right.

What else could it be?”

If not, they'll will be stuck inside the loop forever! Make sure you give the user a chance to enter the correct password. Click on this code to test it. The character asks for the password. To make sure the “repeat until” loop works, first type an incorrect answer. This example enters “cat.”

Since the condition “answer = scratch” was not met, the code inside the repeat loop will execute. For this example, that code asks “That was not correct, what else could be?” Try one more incorrect test. 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.

If you would like your story to wait to start until the correct password is entered, place the code you just created 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 = 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.

Scegli un’estensione
Cammina
In questo video scoprirai come fare avvicinare il personaggio alla porta e come farlo allontanare.
Qual è la password?
Con questo componente, programmerai una password segreta che l'utente dovrà inserire per attraversare la porta segreta.
Fai piovere
Con questo componente, scoprirai come usare la valigetta per inserire nel progetto la pioggia che hai creato durante la terza giornata.
Trova la porta segreta
Con questo componente, farai muovere il personaggio su comando dell'utente con i tasti freccia.
Aggiungi un altro personaggio
Con questo componente aggiuntivo, inserirai nella storia altri personaggi.
Aggiungi un'altra scena
In questo componente ti guiderò nell'aggiunta di una nuova scena e ti darò qualche suggerimento su come programmarla.
arrow_backward Indietro
Avanti arrow_forward
Istruzioni
  1. Scegli un componente aggiuntivo e fai clic su "Guarda" per scoprire come costruirlo.
  2. Una volta terminato un componente aggiuntivo, scegline un altro da provare!