Back to all Refresher Lessons
Broadcasting: Surprise Party Example
First, we're going to use the Complex Arrow Key Movement Lesson to make your berryBro move. I changed the movement from arrow keys to WASD because I prefer it. You can use whatever you want.

Now, click on the background sprite draw your hallway. The only important part of this is that you need a door that's a different color than anything else in your game.

Click on the paintbrush to add another backdrop and draw the room where your surpirse party will take place. I've added a couch. You don't need a couch. You do need to name your backdrops like I have.

Click back to your berryBro and his scripts.
In events, drag in a [when green flag clicked]. If you click your green flag right now, the background is of the second room, not our starting room. Add a [switch backdrop to (hallway)] block. Put a [forever] and an [if] under it.

We're going to tell your berryBro that when he's touching the color of your door, partyTime has begun and the backdrop should change.
In sensing, drag the [touching color ()] block into your [if]. Click into the color and then click on your door. Now get a [switch backdrop to (partyRoom)] block and put it in the if.
Test your code! The room should change when you get to the door.

Now the most important part. in Events, get a [broadcast (message)] block and make a new message called partyTime. Put this block under your [switch backdrop to (partyRoom)] block. Right now, no one is listening for the partyTime message so nothing new is going to happen when you test your code.

Your berryBro needs friends to wish him a happy birthday! Make as many new sprites as you think is right. I've made a delicious fruit salad of friends.

These friends are the ones that have to listen for the broadcast! When the green flag is clicked and your game started, they should all be hidden so it's a surprise. Give them (all of them!) a [when green flag clicked] telling them to go to their positions and then hide.

Now give your first friend a [when I recieve (partyTime)] with instructions to [show] and say something cute!
You can just click and drag that code to each of your friends so you don't have to recode it all, just change the things they say. Test your game!

The only weird bit right now is where the berryBro is when he gets to the partyRoom. Give him instructions to go to where the door of the room would have put him after he broadcasts partyTime.
Now send your sweet berryBro into his surprise party! You've used broadcasting successfully.