arrow_back Add a Third Character
In this add-on, you’ll add a third sprite to your story using a “broadcast” block.
So far, you’ve sequenced dialogue using “wait” blocks. That works great with two sprites, but it can get complicated in longer stories and stories with more than one character.
The “broadcast” block makes complex stories easier to organize.
To start, plan for a third sprite in your story. In this example, a sprite will come in at the end and say a closing line. Select a third sprite for your project. This example will use a butterfly, but you can select any sprite you like. Then, program that sprite’s actions. This sprite starts at the top left.
Then glides to a position next to the duck. It then says, “We’ll miss you!” Click it to try it out.
Now that the basic programming is in place, it’s time to sequence this code with the rest of the story.
You could do this using “wait” blocks. However, you can also use a “broadcast” block.
The butterfly should run this code after the duck finishes talking. To do this, select the duck, go to the events menu, and place a broadcast block on the end of the block stack. Click the dropdown menu, and select “new message.” Name the message something that describes what the code will do. This example will use “Butterfly’s entrance.” When the “broadcast” block runs, it will send this message to the other sprites. The butterfly now needs to be programmed to receive this message. Click events, and drag out a “when I receive” block. Make sure the message name matches the name in the “broadcast” block. In this example, it'll be "Butterfly's Entrance."
Try it out!
Great! It works, but the sprite should go to the top left corner at the beginning of the program. Drag the “go to” block off the “broadcast” block, and instead have this code run when the green flag is clicked.