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 Célébration


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.

Choisir une extension
Programme une célébration lorsque le frappeur réalise une moyenne parfaite.
Effet d’optique
Donne à la balle une apparence plus réaliste lorsqu'elle s'approche ou s'éloigne des buts.
Indique au frappeur s'il a battu le record enregistré jusqu'ici.
Tir au but
Programme le son des acclamations du public.
Ligue nationale
Fais raconter une histoire par le lanceur avant le début du jeu.
Simuler le mouvement
Anime le lanceur afin qu'il ou elle donne l'impression de se déplacer.
arrow_backward Retour
Suivant arrow_forward
  1. Choisis une extension, et clique sur "Regarder" pour découvrir comment personnaliser ton projet.
  2. Quand tu as fini, reviens à la fenêtre des extensions et essaies-en une autre !