In the last video, you made both characters talk, but they talk at the same time.
One solution would be to put wait blocks between the speak blocks, but placing all of those wait blocks would get tedious.
Instead, control who is talking by creating a variable that keeps track of whose turn it is to talk.
Make a variable...
and name it something that makes sense, like "person talking."
Isabel should wait to talk until "person talking" equals "Isabel".
Place a wait until block under the define speak block.
Add an equals block inside the wait until block, and place the person talking variable on one side of the equals block.
Type Isabel on the other side.
If you renamed this sprite, type in the name you selected.
Next, set the variable to Isabel when Malik is done talking.
Click on the Malik talk sprite.
Place the set variable block at the end of the speak function definition.
Type Isabel in the box.
Click the flag again.
Isabel waits to speak until Malik is done talking.
But Malik doesn't wait for Isabel.
Testing the code uncovered a bug or mistake that needs to be fixed.
Make sure to test your code often so you can catch bugs early!
To make the characters wait their turn to talk, add the same code to Malik that you added to Isabel.
Place a wait until block under the speak define block definition.
Add an equals block inside the wait until block.
Place the person talking block on one side of the equals block, and type Malik on the other side.
Finally, change the person talking variable when Isabel is finished talking.
Click on the Isabel talk sprite, and set person talking to Malik.
Click the flag.
Both characters wait their turn to talk, but Isabel talks first.
That's because person talking is still set to Isabel.
You found another bug in the code by testing often.
Set person talking at the beginning of the program, to the character that should start the conversation.
Place the set variable block under the one flag clicked box.
In the box type the character who will start the conversation.
In this example, it's Malik.
Click on the Malik talk sprite and do the same thing.
Now, both sprite know to start with Malik talking.
Run the code again.
The conversation happens in the right order, because both sprites now wait their turn to talk using variables.
The wait blocks are no longer needed.
Remove the wait blocks from both sprites.
Test the code once more.
Functions make fixing bugs in code easier.
Once you fix on part of a function, it is fixed for each time you use it.
If you work using functions you would need to change who's speaking between each say block.
Instead you need to fix this error only once for each sprite.
Now that you've built the functions to easily create a dialog.
It's time to write it.
In this example story, Malik and Isabel work our their differences and decide to have pizza.
Functions make it easier to write longer more interesting conversations, because you can add more lines of dialog, switch between speakers, and add emotions without writing new stacks of code.
Add more speak blocks to the project to create your own dialog.
Create any kind of conversation; funny, heartfelt, silly, tragic, friendly.
With the help of computer science.
Now it's your turn.
Change whose turn it is to speak set person talking and wait until blocks.
Set person talking to the first character in both "Malik talk" and "Isabel talk."
Delete the wait blocks.
Create a conversations between the two characters.
- Change whose turn it is to speak using "set person talking" and "wait until" blocks.
- Set "person talking" to the first character in both "Malik talk" and "Isabel talk."
- Delete the "wait" blocks.
- Create a conversation between the two characters.