Now that you have a way to count hits, you can calculate the hitter’s batting average.
In this video, you’ll learn how to reveal the batter’s average at the end of the game.
Over time, this information will show the player’s growth and development as a hitterand player.< To start, click on the coach sprite.
In baseball, a player’s batting average is the number of hits divided by the numberof times up at bat. For this game, the batting average will be the number of hits dividedby the number of pitches. From the "operators" menu, drag out the “division”block. From the "data" menu, place “hits” inthe first blank of the division block. Type 5 – or the number of pitches you chosefor your game – in the second blank of the “division” block.
Click on the division block. It shows the value of hits, in this case 2, divided bythe number of pitches, which is 5. 2 divided by 5 is 0.4. Nice.
To make the coach say this value, go to the “looks” menu and drag out a “say for2 seconds” block, then drag your division block into the say block.
Click on the block. The coach says 0.4. Place another “say” block above this onethat explains the number. This example says, “Your batting average is.”
Finally, the coach needs to know when all the pitches have been thrown before sayingthe batting average. Click on the baseball. From the “events”menu, drag out a “broadcast” block, and place it at the end of the "repeat" loop.
To name the message something that makes sense, click on “new message,” then type in anew name. This example uses “calculate.” Click the coach. From the "events" menu, placea “when I receive” block on top of the stack that makes the coach say the battingaverage. Click the flag to test your game. Try it afew times. What the coach says should change depending on how many times you hit the ball.
If you score zero hits out of five, for example, the coach says “your batting average iszero.” If you hit the ball three times, the batting average is point six.
Here's the game plan: Calculate the batter’s batting average usinga “division” block and the “hits” variable.
Make the coach say the batting average. And finally, let the coach know when to saythe value using “broadcast” and “when I receive” blocks.
Once you complete these steps, you're done with the core project! Move onto the nextpage to add some sweet add-ons to the batter up project.