Coding Activity: A Two-Way Conversation.
Objective: To create a two-way conversation between two characters.
Required Block Categories: Text to Speech, Events, and Motion
Sprites needed: Fairy, Prince, and Princess
Backdrops needed: Castle 3
To have a two-way conversation between two sprites, we need to exchange messages between the two. Besides, we need one Sprite to send a message when done talking so that the other Sprite can respond. We can achieve a two-way conversation either by using wait block to time and delay a sprite before responding or by using broadcast messages. Broadcast messages are the best option to guarantee a smooth and accurate conversation.
How Broadcast Messages work
Once a sprite has spoken, you create and send a broadcast message received by the other Sprite. The broadcast message should have a unique name that is relevant to the words being spoken. Besides, it is possible, where necessary, to have more than one Sprite respond to one message from one specific Sprite.
Blocks related to broadcast messages can be found under the Events category and include when I receive message, broadcast message, and broadcast message and wait. Broadcast message block allows you to send a message while the when I receive message executes/performs a given instruction/action once the broadcast message is received. Remember, the message name will keep changing depending.
Creating a New Broadcast Message
To create a new broadcast message, drag the broadcast block to your workspace, click on the dropdown under “message 1” below.
Select the “New message” button to open an editor where you can specify a preferred name for the new broadcast message. For example, write the word demo as your message name.
Receiving a broadcast message
Use the “when I receive” block. Make sure to click the dropdown to select the appropriate message you intend to act on. You can only see the messages you have created and nothing more. Hence, the dropdown will display only a list of messages in the current project.
Story Overview: A conversation is happening between Prince and Princess. The conversation starts with the Prince greeting his sister, the Princess. There is a third person, who the Prince is interested to know. Besides, the Prince is just coming from a meeting and the Princess is interested in learning its outcome. ENJOY!!!
Create a new project and add the Castle 3 backdrop and the three sprites (Fairy, Prince, and Princess) as shown in the screenshot below.
STEP 2: Begin with coding the Prince
Choose the Prince to add the text-to-speech block to let him start the conversation. You will set Prince’s voice to tenor before making him speak the following sentences/statements: “Hello Princess” and “How is the going.” Then send a broadcast message called “greetings” using the broadcast message block. See the screenshot below:
STEP 3: Princess responds to the greetings
Select the Princess. Add the go-to block to set her initial start position on the stage. However, you will not add the text-to-speech block immediately after the go-to(x, y) block for the Princess to respond to the greeting after receiving the Greetings broadcast message. Therefore add your blocks in the order shown on the screenshot and click the green flag to test your program.
Ensure that when I receive block points/shows the correct message name you wish to receive in your conversation. Therefore add the following blocks to respond to the Prince’s greetings.
STEP 4: Princess sends a message back to Prince
You can think of this program as a scenario where two guest speakers use one mic to speak to one another, especially as they try to know each other. Therefore when the first is done, he/she will return the mic to the second speaker to say something else, and the conversation continues. Besides, you can think of the broadcast messages as signals or controls that allow each person to know when it’s their turn to speak. Therefore, we can assume the Princess is giving back control to Prince or sending a signal back to the Prince.
Let Princess send another new broadcast message to be received by the Prince, but before she will ask “what about you?” from where you will derive the name of your next broadcast message.
STEP 5: Prince Responds and asks about the third person
You will make the Prince tell the Princess how he is doing, after which, he asks about the third person accompanying the Princess.
STEP 6: Princess reveals who the third person
You now understand how everything is flowing. Let’s keep going. Again switch to Princess and receive the who is she message by adding the blocks shown below on Princess. Besides, let Princess send another broadcast message.
STEP 7: Prince receives the guardian angel broadcast message
Add the blocks below:
STEP 8: Princess receives the wonderful broadcast message
In this step, the Princess will inquire about the meeting’s outcome. Add the blocks below:
Your turn to be creative.
Work on the Task below
- Think of two possible responses that Prince can give concerning the meeting he attended with the governing council. Add blocks to allow Prince to speak the responses.
- Think of two possible reactions that Princess would give after hearing Prince’s responses. Add the appropriate blocks to make it work nicely.
- You are free to take the conversation beyond my examples, including creating an entirely new conversation using your favourite sprites.