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 Keep Score


This add-on will make your game more competitive by adding a score that counts the number of times the athlete misses the ball.

To keep score, use a computer science concept called a variable.

Variables are places where computers store information like numbers and phrases.

You'll learn more about them in later activities in this club as well.

First, select the ball sprite.

To make the score variable, click Make a Variable, and type in score.

If you've added a second player, call this variable score1.

Then create a second variable using the same process and call it score2.

Click OK to create the variable, and notice the new blocks that show up telling you the things you can do with your new variable.

Here's a quick overview.

Every time you click the flag, the score variable or variables should reset to zero, then every time the ball sprite moves past the athlete and hits the red goal line, the first player score variable should go up by one.

The same should happen for the second player, so the lower your score, the better you are at the game.

First, build the scoring conditional.

If the ball sprite is touching the red part of the stage, the score should go up.

Start with an if block.

The condition is that the ball sprite must be touching red.

From Sensing, drag out touching color and snap it in as the condition.

To select the right color to detect, click the square swatch in the block, then the stage, and click the red goal area.

Check that the right color is selected.

Click the change by block.

When you do this, the number inside score goes up by one.

Place this block inside the condition.

If you click the whole stack now, nothing happens unless you drag the ball sprite into the red goal area.

Click again.

Success, the score goes up by one.

To make this work for two players, right click and duplicate the whole if block, then snap the duplicated stack below.

In the second conditional, choose the blue goal two color and the score2 variable in the change by block.

Whether you're building this add-on for one sprite or two, the ball sprite should continue checking if the goal is scored, so drag a forever loop around the conditional stack.

Top off the stack with a when flag click block, but remember that the score needs to be reset to zero at the start of each new game.

Do this by placing a set two block right under the event, but not inside the forever loop.

If you have a second player, do this for their score as well.

Test and see what happens.

You may notice that whenever the ball hits the goal area, the score goes up by more than one.

Look at the code and try to figure out why.

As soon as the score increases, the code loops back to the beginning.

Wait, it goes through so quickly that the ball is still touching the red, so the score increases again.

To fix this, add a wait block after the change by block inside the if block.

Two seconds is fine, and it fixes the problem.

All right, here's the game plan.

Make one or two variables to keep track of the score.

Use a forever block, an if block, a touching color block, and a change by block to make sure the score increases by one each time the goal is scored.

Start the script with an event and reset the score or scores to zero.

Choose an Add-On
Bounce Reaction
Program the ball sprite to do or say something when it bounces.
Second Player
Add a second athlete to make a two player game.
Keep Score
Add a score counter to the game.
Play the Computer
Program a sprite to play against the user.
arrow_backward Back
Next arrow_forward
  1. Choose an Add-On, and click "watch" to learn how to build it.
  2. Once you finish one Add-On, try another one below the video!