Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Points jumping up
- Yaninastarr
-
New Scratcher
5 posts
Points jumping up
Hello,
I have created my first game in scratch but the points jump up in increments of about 10 instead of 1, can anyone please help?
https://scratch.mit.edu/projects/713822849
I have created my first game in scratch but the points jump up in increments of about 10 instead of 1, can anyone please help?
https://scratch.mit.edu/projects/713822849
when green flag clicked
forever
if touching ball then
change score by 1
- cIoudyness
-
Scratcher
500+ posts
Points jumping up
that’s because the ball touches the white circle for, say, eight frames. a solution:
when the white circle notices it’s touching a ball it broadcasts a message and waits 0.2 seconds. in the golden ball sprites, when they receive the message, they check to see if they’re touching the white circle. if they are then they jump back to the start on the right
or you could have three different messages so you know which ball needs to go back without detecting touching another time
by the way the “fix overlap” custom should be set to run without screen refresh
when the white circle notices it’s touching a ball it broadcasts a message and waits 0.2 seconds. in the golden ball sprites, when they receive the message, they check to see if they’re touching the white circle. if they are then they jump back to the start on the right
or you could have three different messages so you know which ball needs to go back without detecting touching another time
by the way the “fix overlap” custom should be set to run without screen refresh
- RT_Borg
-
Scratcher
1000+ posts
Points jumping up
Hi Yaninastarr, welcome to Scratch!
Very nice first project!!
This was tricky to figure out, because there are actually 3 things about the code that make scoring look like this.
I made a remix of the project that shows how each can be fixed. But more important is to understand what's happening, so you'll know in future games.
FOR HELP Tweet - remix 2 repair score
https://scratch.mit.edu/projects/715568031
Issue 1. As is often the case with “touching”, when sprites are moving past one another (or even when people try to “bounce” by changing direction) often they'll stay touching for a small amount of time. If you don't do something about this, every time your loop checks “if touching” it will be true during that short time, and you'll score each time.
A typical way to deal with this is to wait until the two sprites are no longer touching before checking “touching” again. There's a “wait until” block that can help with this.
I made a change to put Ball1,2,3 sprites be in charge of scoring. I removed the scoring script in Ball 4 and gave each of Ball1,2,3 a scoring loop. (I'll say more about why at the end.)
You'll see it “wait until not touching” used in each of the Ball1,2,3 sprites. The new variable “SCORE” is “For all sprites” (shared by all sprites) and replaces the old “Score”, that was “For this sprite only”.
Issue 2. In the movement loops for Ball1,2,3, they
The problem here was that when they hide, they're at the position where they touched Ball 4. So then they hide, wait, and show again – all before returning to the starting position. When they show (still at the position of Ball 4) that's another touch.
I fixed this by going always going to the starting position immediately after the glide (just before the hide).
Issue 3. This one isn't a problem with the scoring, but to the player looks like it is. Because of the timing that balls start, sometimes there are 2 balls exactly on top of each other. So it looks like only 1 ball gets to the white spot, but really there are more than 1, and each scores.
I changed the costumes to arrows (colored differently, and pointed in different directions) and applied a ghost effect on them (partial transparency) so you can easily see that there are sometimes 2 arrows on top of one another (each scoring).
If you have any questions about what I changed in the remix, or why, please ask.
So why did I move scoring?
Ball 4 really could have stayed in charge of scoring. It would need 3 separate scripts, one each to check each of Ball1,2,3 (so it could deal with the touching/not-touching situation for each of them). So the code would have been fairly similar.
I moved scoring to Ball1,2,3 because there's a next thing you could do to really simplify the project.
Preview: That would be to replace all three Ball1,2,3 sprites with a single Ball that “clones” itself, and uses a random value to set delays between new balls being launched, and another random value to set the speed. (As time passes, the range of delay values can get smaller and the range of speeds can get bigger, so the game gets harder and harder.)
If you'd like to learn about clones, this is really a perfect project for it. I would be willing to make another remix, and explain it, if you wouldn't mind me using the different versions as a small tutorial for other new scratchers in the future.
– RT_Borg
Very nice first project!!

This was tricky to figure out, because there are actually 3 things about the code that make scoring look like this.
I made a remix of the project that shows how each can be fixed. But more important is to understand what's happening, so you'll know in future games.
FOR HELP Tweet - remix 2 repair score
https://scratch.mit.edu/projects/715568031
Issue 1. As is often the case with “touching”, when sprites are moving past one another (or even when people try to “bounce” by changing direction) often they'll stay touching for a small amount of time. If you don't do something about this, every time your loop checks “if touching” it will be true during that short time, and you'll score each time.
A typical way to deal with this is to wait until the two sprites are no longer touching before checking “touching” again. There's a “wait until” block that can help with this.
I made a change to put Ball1,2,3 sprites be in charge of scoring. I removed the scoring script in Ball 4 and gave each of Ball1,2,3 a scoring loop. (I'll say more about why at the end.)
You'll see it “wait until not touching” used in each of the Ball1,2,3 sprites. The new variable “SCORE” is “For all sprites” (shared by all sprites) and replaces the old “Score”, that was “For this sprite only”.
Issue 2. In the movement loops for Ball1,2,3, they
- go to the starting position (on the right)
- glide (to the position of Ball 4 target)
- hide
- wait 3 seconds (still positioned at the same place as Ball 4)
- show <——————-
- … (and repeat, go to starting position again)
The problem here was that when they hide, they're at the position where they touched Ball 4. So then they hide, wait, and show again – all before returning to the starting position. When they show (still at the position of Ball 4) that's another touch.
I fixed this by going always going to the starting position immediately after the glide (just before the hide).
Issue 3. This one isn't a problem with the scoring, but to the player looks like it is. Because of the timing that balls start, sometimes there are 2 balls exactly on top of each other. So it looks like only 1 ball gets to the white spot, but really there are more than 1, and each scores.
I changed the costumes to arrows (colored differently, and pointed in different directions) and applied a ghost effect on them (partial transparency) so you can easily see that there are sometimes 2 arrows on top of one another (each scoring).
If you have any questions about what I changed in the remix, or why, please ask.
So why did I move scoring?
Ball 4 really could have stayed in charge of scoring. It would need 3 separate scripts, one each to check each of Ball1,2,3 (so it could deal with the touching/not-touching situation for each of them). So the code would have been fairly similar.
I moved scoring to Ball1,2,3 because there's a next thing you could do to really simplify the project.
Preview: That would be to replace all three Ball1,2,3 sprites with a single Ball that “clones” itself, and uses a random value to set delays between new balls being launched, and another random value to set the speed. (As time passes, the range of delay values can get smaller and the range of speeds can get bigger, so the game gets harder and harder.)
If you'd like to learn about clones, this is really a perfect project for it. I would be willing to make another remix, and explain it, if you wouldn't mind me using the different versions as a small tutorial for other new scratchers in the future.
– RT_Borg
- Yaninastarr
-
New Scratcher
5 posts
Points jumping up
That's great! Thank you both so much for your feedback I really appreciate it.
- Yaninastarr
-
New Scratcher
5 posts
Points jumping up
-RT_Borg You are welcome to use my game in your tutorial as long as you mention my name and say that I created it.
- RT_Borg
-
Scratcher
1000+ posts
Points jumping up
Hi Yaninastarr,
Thanks. Here's what I'm thinking of turning into the tutorial. The notes below are just a draft, but please let me know if you think it makes sense, or where I should add more detail/explanation.
You'll want to open Part 2 (the remix I shared before) and Part 3 (the new remix) to follow the notes and see how I turned the 3 ball sprites into a single sprite that uses clones.
Part 2: https://scratch.mit.edu/projects/715568031/
Part 3: https://scratch.mit.edu/projects/715950584/
Notes: Sprites to Clones Tutorial - Part 3
(Replace Ball 1-3 with a single Challenge sprite)
Renamed Ball4 to Goal
Duplicated Ball to make a Challenge sprite.
Simple forever loop for the green flag that creates clones. Moved “set SCORE to 0” from goal to the top of this green flag script.
Both other green flag scripts become “when I start as a clone” instead, because those are the things each clone will do.
Delete the Ball1, Ball2, Ball3 sprites.
Version 1
Now balls the game works, with Challenge clones moving toward the goal every 2 seconds (fast enough that there's more than one clone on the screen at a time.)
This is already playable, but now we'd like to make it a little more random than a Challenger every 2 seconds.
Version 2
Next change is to pick a random number instead of 2, making Challengers come every 1.5 to 2.5 seconds. The balls come with random delays now, which makes it more interesting.
Version 3
Now let's add some randomness to the speed the balls move. We can do this by putting another random number (3.5 to 4.5) in the glide block instead of 4. This is under the first “when I start as clone”.
Nice. With the random delay between clones and the random glide time, it's definitely more fun. But it isn't that much of a challenge.
Version 4
Let's shorten the delay just a little bit on each jump. We can do that by making the values in our “pick random” block get a little smaller over time. There are a lot of ways we could do this.
Trying a couple things, I decided the shortest delays were already short enough, and settled on only reducing the top of the random range so it gets more challenging.
1.5 to 2 + 1/(score + 1)
The top of the random range changes like
score 0: 2 + 1/(0 + 1) = 2 + 1/1 = 3
score 1: 2 + 1/(1 + 1) = 2 + 1/2 = 2.5
score 2: 2 + 1/(2 + 1) = 2 + 1/3 = 2.333
…
approaching 2 over time.
You could also do something simlar to shorten glide times as the score grows, but it feels pretty good at this point.
Finally, add a switch costumes block in “when I start as clone” to a random costume. I'll pick the top of my random range to be how many costumes I have.
Great! (Except I left the arrow costume in.) I'll remove the arrow, add some more costumes from the scratch library, and change my random range for the right number of costumes.
Thanks. Here's what I'm thinking of turning into the tutorial. The notes below are just a draft, but please let me know if you think it makes sense, or where I should add more detail/explanation.
You'll want to open Part 2 (the remix I shared before) and Part 3 (the new remix) to follow the notes and see how I turned the 3 ball sprites into a single sprite that uses clones.
Part 2: https://scratch.mit.edu/projects/715568031/
Part 3: https://scratch.mit.edu/projects/715950584/
Notes: Sprites to Clones Tutorial - Part 3
(Replace Ball 1-3 with a single Challenge sprite)
Renamed Ball4 to Goal
Duplicated Ball to make a Challenge sprite.
Simple forever loop for the green flag that creates clones. Moved “set SCORE to 0” from goal to the top of this green flag script.
Both other green flag scripts become “when I start as a clone” instead, because those are the things each clone will do.
Delete the Ball1, Ball2, Ball3 sprites.
Version 1
Now balls the game works, with Challenge clones moving toward the goal every 2 seconds (fast enough that there's more than one clone on the screen at a time.)
This is already playable, but now we'd like to make it a little more random than a Challenger every 2 seconds.
Version 2
Next change is to pick a random number instead of 2, making Challengers come every 1.5 to 2.5 seconds. The balls come with random delays now, which makes it more interesting.
Version 3
Now let's add some randomness to the speed the balls move. We can do this by putting another random number (3.5 to 4.5) in the glide block instead of 4. This is under the first “when I start as clone”.
Nice. With the random delay between clones and the random glide time, it's definitely more fun. But it isn't that much of a challenge.
Version 4
Let's shorten the delay just a little bit on each jump. We can do that by making the values in our “pick random” block get a little smaller over time. There are a lot of ways we could do this.
Trying a couple things, I decided the shortest delays were already short enough, and settled on only reducing the top of the random range so it gets more challenging.
1.5 to 2 + 1/(score + 1)
The top of the random range changes like
score 0: 2 + 1/(0 + 1) = 2 + 1/1 = 3
score 1: 2 + 1/(1 + 1) = 2 + 1/2 = 2.5
score 2: 2 + 1/(2 + 1) = 2 + 1/3 = 2.333
…
approaching 2 over time.
You could also do something simlar to shorten glide times as the score grows, but it feels pretty good at this point.
Finally, add a switch costumes block in “when I start as clone” to a random costume. I'll pick the top of my random range to be how many costumes I have.
Great! (Except I left the arrow costume in.) I'll remove the arrow, add some more costumes from the scratch library, and change my random range for the right number of costumes.
- Discussion Forums
- » Help with Scripts
-
» Points jumping up