Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » my score doesn't go up correctly
- theRooook
-
Scratcher
3 posts
my score doesn't go up correctly
I'm making a game where when you click something the score should go up by 1 but it goes up random amounts.
How do I fix this?
How do I fix this?
- UnconstructivePoster
-
New Scratcher
100+ posts
my score doesn't go up correctly
Can you share the project and provide a link? It's easier for people to give help if we can look at your actual code.
Are you perhaps doing something like this?
If so, what's happening is that you're checking whether the mouse is being held down every time the forever loop runs instead of detecting individual clicks. If there's nothing else in the loop, you could fix this by adding something like wait until <not <mouse down?>>.
If there's other code in the loop, the wait block would interfere with it. Instead, you could introduce a variable that stores whether the mouse is currently being held down and prevents the score from increasing by more than one.
Are you perhaps doing something like this?
forever
if <mouse down?> then
change [score v] by [1]
end
end
If so, what's happening is that you're checking whether the mouse is being held down every time the forever loop runs instead of detecting individual clicks. If there's nothing else in the loop, you could fix this by adding something like wait until <not <mouse down?>>.
If there's other code in the loop, the wait block would interfere with it. Instead, you could introduce a variable that stores whether the mouse is currently being held down and prevents the score from increasing by more than one.
forever
other code :: #aaaaaa
if <<mouse down?> and <(mouse held?) = [0]>> then
change [score v] by [1] // since this only runs if the mouse isn't already being held, the score only increases once
set [mouse held? v] to [1]
else
set [mouse held? v] to [0]
end
other code :: #aaaaaa
- SultanGames
-
Scratcher
32 posts
my score doesn't go up correctly
Can you share the project and provide a link? It's easier for people to give help if we can look at your actual code.Another solution to that could be to just add a wait block. It will prevent people from using autoclickers too. The only downside is that if people actually have good cps (clicks per second) it'll not register all.
Are you perhaps doing something like this?forever
if <mouse down?> then
change [score v] by [1]
end
end
If so, what's happening is that you're checking whether the mouse is being held down every time the forever loop runs instead of detecting individual clicks. If there's nothing else in the loop, you could fix this by adding something like wait until <not <mouse down?>>.
If there's other code in the loop, the wait block would interfere with it. Instead, you could introduce a variable that stores whether the mouse is currently being held down and prevents the score from increasing by more than one.forever
other code :: #aaaaaa
if <<mouse down?> and <(mouse held?) = [0]>> then
change [score v] by [1] // since this only runs if the mouse isn't already being held, the score only increases once
set [mouse held? v] to [1]
else
set [mouse held? v] to [0]
end
other code :: #aaaaaa
Code:
when green flag clickedIt'll allow a max of 10 cps
forever
if <mouse down?> then
change [score v] by (1)
wait (0.01) secs
end
end
Last edited by SultanGames (July 13, 2023 20:07:41)
- UnconstructivePoster
-
New Scratcher
100+ posts
my score doesn't go up correctly
This approach wouldn't prevent someone from gaining multiple points by holding down the mouse button for longer than the duration of the wait. If you want to make sure they can only get one point per click no matter how long they hold, you'd need to use an approach like the ones I mentioned to detect when the mouse button is released.Can you share the project and provide a link? It's easier for people to give help if we can look at your actual code.Another solution to that could be to just add a wait block. It will prevent people from using autoclickers too. The only downside is that if people actually have good cps (clicks per second) it'll not register all.
Are you perhaps doing something like this?forever
if <mouse down?> then
change [score v] by [1]
end
end
If so, what's happening is that you're checking whether the mouse is being held down every time the forever loop runs instead of detecting individual clicks. If there's nothing else in the loop, you could fix this by adding something like wait until <not <mouse down?>>.
If there's other code in the loop, the wait block would interfere with it. Instead, you could introduce a variable that stores whether the mouse is currently being held down and prevents the score from increasing by more than one.forever
other code :: #aaaaaa
if <<mouse down?> and <(mouse held?) = [0]>> then
change [score v] by [1] // since this only runs if the mouse isn't already being held, the score only increases once
set [mouse held? v] to [1]
else
set [mouse held? v] to [0]
end
other code :: #aaaaaa
Code:when green flag clickedIt'll allow a max of 10 cps
forever
if <mouse down?> then
change [score v] by (1)
wait (0.01) secs
end
end
- YoshiGirl153
-
Scratcher
500+ posts
my score doesn't go up correctly
One way you can fix this is by using this:
when green flag clicked
forever
if <mouse down?> then
change [score v] by (1)
wait until <not <mouse down?>>
end
end
- YEONJUN_0112
-
New Scratcher
1 post
my score doesn't go up correctly
I'm making a game where when you click something the score should go up by 1 but it goes up random amounts.
How do I fix this?
- Discussion Forums
- » Help with Scripts
-
» my score doesn't go up correctly