Skip to content

Please update your browser

Your browser version is not supported by this site. CS First may not work properly. Learn more

arrow_back Celebration


In this add-on, you will program a celebration for when the batter achieves a perfect batting average. Start by programming the celebration. This can be any fun action or animation! For example, you might make the stadium flash different colors using the “change color effect,” “wait,” and “repeat” blocks.

Or, make your celebration a sound. To add a sound to your project, click on the “sound” tab, and click “choose sound from library.” To listen to the sounds, click the play buttons next to each. Then, choose one you like, and click “OK.” To learn more about sounds in Scratch, check out the “out of this ballpark” add-on, then come back to this one.

In your celebration, the coach could also congratulate the batter.

There are many possible celebrations! Use the ideas here, combine them, or come up with your own! Build the code for the celebration actions, but don't connect them to any other code or event yet. The second part of this video will show you how to add the celebration to your game. Once you finish creating a celebration, test it by clicking the code. Tinker with the code until you are happy with your celebration.

Now, tell the program when to run the celebration. Click the coach sprite. The celebration will happen after the coach sprite tells the batter the batting average. To let other sprites know when the coach is finished talking, go to the "events" menu, and drag out a “broadcast” block. Place it after the coach says the batting average. Click on the dropdown, then select “new message” and give it a name like “Celebration.”

Next, program the celebration code to receive that message. If multiple sprites or the stage have blocks, you'll complete these same steps for all of them. From the “events” menu, place a “when I receive” block above the code for the celebration. Click the dropdown, and select the name of your message.

Test the code. After five pitches, the coach says the batting average, then the celebration happens. But the celebration is only supposed to happen *if* the batter got a perfect score! From the “control” menu, place an “if/then” block around the “broadcast” block. Fill out the condition. If the batter got a perfect average, the batting average will equal 1. From the “operators” menu, place the “equals” block in the “if/then” block. To check if the batting average equals one, type 1 on either side of the “equals” block. The other side will contain the batting average. Right click on the “batting average” equation in the “say” block, and select duplicate. Place the duplicate code in the other side of the “equals” block. Test the code. Practice batting until you get a perfect batting average. When the coach says, “Your batting average is 1,” the celebration should begin.

Here's the game plan: First, program the celebration.

Then, use the “broadcast” and “when I receive” blocks to let Scratch know when to make the celebration happen. Finally, place the broadcast block inside an “if/then” statement. Use the “equals” block and copy the “hits” and “divide” blocks to create the condition.

Choose an Add-On
Program a celebration for when the batter achieves a perfect batting average.
Over the Plate
Make the baseball look more realistic as it approaches or moves away from the plate.
High Score
Tell the batter if it has beaten the best batting average so far.
Out of this Ballpark
Program the sound of a cheering crowd.
In the Big Leagues
Make the pitcher tell a story before the game starts.
Going through the Motions
Animate the pitcher so it looks like he or she is moving.
arrow_backward Back
Next arrow_forward
  1. Choose an add-on and click "Watch" to learn how to customize your project.
  2. When you finish, come back to the add-ons screen, and try another add-on!