- [Instructor] Now that you have a way to count hits,
you can calculate the hitters batting average.
In this video you'll learn how
to reveal the batters average at the end of the game.
Over time this information will show the players growth
and development as a hitter and player.
To start click on the coach sprite.
In baseball a player's batting average is the number
of hits divided by the number of times up at bat.
For this game the batting average will be the number
of hits divided by the number of pitches.
From the operator's menu, drag out the division block.
Place hits in the first blank of the division block.
Type five or the number of pitches you chose
for your game in the second blank of the division block.
Click on the division block.
It shows the value of hits, in this case two divided
by the number of pitches, which is five.
Two divided by five is point four, nice.
To make the coach say this value go to the looks menu
and drag out a say for two seconds block.
Then drag your division block into the say block.
Click on the block.
The coach says point four.
Place another say block above this one
that explains the number.
This example says your batting average is.
Finally the coach needs
to know when all the pitches have been thrown,
before saying the 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 a new name.
This example uses calculate.
Click the coach.
From the events menu place a when I receive block on top
of the stack that makes the coach say the batting average.
Click the flag to test the game.
Try it a few 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 is zero.
If you hit the ball three times,
the batting average is point six.
Alright here's the game plan.
Calculate the batter's batting average,
using a division block and the hits variable.
Make the coach say the batting average.
And finally let the coach know when
to say the value using broadcast and when I receive blocks.
Once you've got all these steps completed,
you're done with the core project.
Move on to the next page to add some sweet add-ons
to the batter up project.
Sign in to save your project and track your progress.