Now that you've designed your story by adding two sprites and a backdrop, it's time to sequence some dialog to develop your plot.
Watch the video to learn how to do it and then try it on your own.
Remember today's challenge, to create a story driven by a dialogue between two characters, and do this without using questions.
In the previous step, you should have added a save for two 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 save for two 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 it's too cold here for a duck?
It is because the duck was bullied by the penguin?
Did the duck do something wrong and run away, only to come back now?
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.
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 save 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 save 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.
Events tell the computer when to run code.
An event can be something like clicking on a sprite, or 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 out a when green flag clicked block on top of each saved block for both sprites.
Now click the green flag to try it out.
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 a second character's dialogue.
The first character says its statement for two seconds, so the second sprite should wait two seconds before saying its statement.
Click control, select a wait one second block, and place it before your second character's saved block, and change its value to two seconds.
Try this out now by clicking the green flag.
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 reread your code to try and locate the error.
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.
Now it's your turn.
First, add a save for two seconds block with dialogue to your second sprite.
Second, add a when flag clicked event to the code for each sprite.
Third, make the second sprite wait for two seconds before starting its dialogue.
And fourth, continue to build out your dialogue using say and wait blocks.
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 that you want to tell.
- Make the second sprite talk as well.
- Start the code for each sprite when the green flag is clicked.
- Make the second sprite wait for the first to finish talking before starting its dialogue.
- Continue to build your dialogue.