Now that you’ve designed your story by adding two sprites and a backdrop, it’s time to sequence some dialogue to develop your plot.
Watch the video to learn how to do it, then try it on your own.
Remember today’s challenge: In the previous step, you should have added a “say for 2 seconds” block for one of your sprites and filled it in with a starter phrase. Now, it’s time to extend the dialogue by adding a response from your other sprite. To do this, click on the second sprite and drag out another “say for 2 seconds” block.
In this example, the penguin sprite says “I didn’t think you’d be here.” Remember that a single line of dialogue can have many different meanings. In this example, why didn’t the penguin think that the duck would be here? Is it because: As a storyteller, it’s up to you to clue your audience in to what the dialogue means.
For this example, the duck is going to respond, “I could say the same thing to you.”
Click this block to try it out.
Great, the duck now says, “I could say the same thing to you.” The two dialogues aren’t sequenced, though.
You can switch back and forth between the two sprites and click on each “say” block every time you want a sprite to say something. But, the beauty of computer science is that you can program the computer to sequence these “say” blocks for you so the dialogue is presented in the right order. You need a way to start the story with one button press, like clicking “play” to start a movie.
In computer science, this type of action is called an “event.”
An event can be something like clicking on a sprite, clicking the green flag, pressing a button, or even sending a message from one part of the program to another. For this example, and for most stories, you’ll use a “when green flag clicked” event to start the story. This is sort of like Scratch’s play button. Go to the events menu and drag a “when green flag clicked” block on top of each “say” block.
Now, click the green flag to try it out. Great! Both sprites say their dialogue. But, there’s a problem. They both say it at the same time!
That’s really confusing for the audience because they won’t know which statement to read first. To fix this, tell the computer to wait before running the second character’s dialogue. The first character says its statement for 2 seconds, so the second sprite should wait two seconds before saying its statement.
Click control, select a “wait 1 second” block, place it before your second character’s “say” block, and change its value to 2 seconds.
You’ve now successfully sequenced code for two sprites to talk to each other. But, a two-line story isn’t that compelling for the audience.
Continue to build out your story from here by sequencing “say” and “wait” blocks between your two sprites so they have a longer and more interesting conversation.
Remember to test your code often so that you can easily spot bugs, or errors, when they occur.
All computer scientists encounter bugs in their code. When that happens to you, it can help to re-read your code to try and locate the error. Ask a neighbor if you find a bug that you’re having difficulty solving on your own. Remember that you can post a sticky note on your monitor to get the attention of your CS First Guru. Once you’ve coded your story, move on to the add-ons and explore some ways to add more action to your story with movement and sound.
Try to challenge yourself by not using any questions in your dialogue! Remember, the writing process requires a lot of testing and reworking. Test your code often, and make sure the code supports the story you want to tell.
- Tu feras aussi parler le deuxième lutin.
- Lance le code de chaque lutin lorsqu’un utilisateur clique sur le drapeau.
- Fais patienter le deuxième lutin jusqu’à ce que le premier ait fini de parler avant de démarrer son dialogue.
- Continue à développer ton dialogue.