Your browser version is not supported by this site. CS First may not work properly. Learn more.
5. Speaking and Responding
Now that you've designedyour story by adding two spritesand a backdrop, it's time to sequencesome dialog to develop your plot.
Watch the video to learn how to do itand then try it on your own.
Remember today's challenge, to create a storydriven by a dialogue between two characters,and do this without using questions.
In the previous step, you should have addeda save for two seconds block for oneof your sprites, and filled it inwith a starter phrase.
Now it's time to extend the dialogueby 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 canhave many different meanings.
In this example, why didn't the penguin thinkthat the duck would be here?
Is it because it's too cold here for a duck?
It is because the duck was bulliedby 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 clueyour 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 betweenthe two sprites, and click on each save blockevery time you want a sprite to say something,but the beauty of computer science isthat you can program the computerto sequence these save blocks for you,so the dialogue is presented in the right order.
You need a way to start the storywith one button press, like clicking playto start a movie.
In computer science, this type of actionis called an event.
Events tell the computer when to run code.
An event can be something like clickingon a sprite, or clicking the green flag,pressing a button, or even sending a messagefrom one part of the program to another.
For this example, and for most stories,you'll use a when green flag clicked eventto start the story.
This is sort of like Scratch's play button.
Go to the events menu, and drag outa when green flag clicked block on topof 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 audiencebecause they won't know which statementto read first.
To fix this, tell the computer to waitbefore running a second character's dialogue.
The first character says its statementfor two seconds, so the second spriteshould wait two secondsbefore saying its statement.
Click control, select a wait one second block,and place it before your second character'ssaved block, and change its value to two seconds.
Try this out now by clicking the green flag.
You've now successfully sequenced codefor two sprites to talk to each other.
But a two-line story isn't that compellingfor the audience.
Continue to build out your story from hereby sequencing say and wait blocksbetween your two sprites so they havea longer, and more interesting conversation.
Remember to test your code often so that youcan easily spot bugs or errors when they occur.
All computer scientists encounter bugsin their code.
When that happens to you it can helpto reread your code to try and locate the error.
Once you've coded your story, move onto the add-ons and explore some waysto add more action to your storywith movement and sound.
Now it's your turn.
First, add a save for two seconds blockwith dialogue to your second sprite.
Second, add a when flag clicked eventto the code for each sprite.
Third, make the second sprite waitfor two seconds before starting its dialogue.
And fourth, continue to build out your dialogueusing say and wait blocks.
Try to challenge yourself by not usingany questions in your dialogue.
Remember, the writing process requiresa lot of testing and reworking.
Test your code often and make sure the codesupports 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.