Now let's create a new stack of code to reset the score and the position of the ball each time a new game is started.
Reset the Score to 0 at the Start of Game
-
In the lower right, ensure that the Ball sprite is selected.
-
From Variables, select the set ( My variable ) to ( 0 ) code block and drag it to the middle.
Note: This is the start of a new stack of code blocks.
-
In the new code block, click the ( my variable ) drop-down and select score.
Center Ball at Start of Game
This moves the ball to the center of the play area when a new game is started (when the green flag is clicked). This is essential, as a previous game probably left the ball at the bottom of the play area.
- From Motion, select the go to x: ( value ) y: ( value ) code block and drag it out to join with the previous code block. This block can be placed above or .
- Click the x: value and change to 0.
- Click the y: value and change to 0.
- At the left, under Events, find the When (
) clicked code block. Add it to the top of your new "stack," for a total of three blocks.
Your finished stack of code blocks should look like this:
![](https://d2jv02qf7xgjwx.cloudfront.net/accounts/353047/images/3rd_ball_code_stack.png)
That's it! You're done! Now you can go play a game you made yourself!
How to Share Your Scratch Project!
You need to have a free Scratch account to save and share programs.
- Go to scratch.mit.edu.
-
In the upper right, select the Sign in button.
-
In the Sign in window, enter your Username and Password and click Sign in.
-
In the upper right, click your Username.
- From the drop-down menu, select My Stuff.
- On the My Stuff page, select either the name of the project to go to the Project Page.
- On the Project Page, fill in any information you wish in the Instructions or the Notes and Credits boxes.
-
In the upper right, click the Share button to make your program public. Now others can try it, leave comments, and remix it to make their own version!
-
In the lower right, select the Copy Link button, so you can send the link to your friends!
-
To make the project private again, return to the My Stuff page and click the Unshare link.