arrow_back Keep Score
This add-on will keep score in your game, so that each time you complete a pass to a receiver, the score will go up. After finishing this add-on, challenge your fellow club members to see who gets the highest score! Go to the data menu, click "make a variable," name it "score," and click "OK." Computers store changing information in variables. In this case, you're going to put the score in the variable, so the computer can keep track of the current score. Next, do two things: start the score at zero, and raise the score by one each time a pass is completed.
To do this, first, click on the ball sprite. At the top of the code stack, just under the "when flag clicked" block, place a "set variable to" block. Make sure that "score" is selected in the dropdown, then enter zero in the value space. This will make the score start at zero every time the flag is clicked. For the second task, make the score go up each time one of the receivers touches the ball. Click on a receiver sprite to see that you've already programmed a conditional that checks if the receiver is touching the football.
Into this conditional, place a "change variable" block. Make sure that "score" is selected in the dropdown, then type “one” into the value blank if it's not there already.
This conditional reads: if the receiver is touching the ball sprite, add one to the score.
Great. But, there are three receiver sprites in this example, and the score should go up if any one of them is touched. Add the same "change variable" block to the script for each receiver sprite in your project. Finally, to see the score, check the box next to the score variable in the data menu. Test it by playing around a bit. Watch the score go up by one each time you hit a receiver, then watch it start over at zero each time you click the flag. Here's the game plan: Make a variable called “score.” Set the score to zero each time the game starts.
Increase the score by one every time a receiver touches the ball sprite.