Discuss Scratch

vivvicmia
New Scratcher
3 posts

Counter

Hello, I am just starting to learn Scratch. I set a counter so that when one sprite touches another one, then the counter should add one point. Both sprites are moving (flying) in opposite directions. But when they touch then the counter goes up by many points since they are actually touching more than once as they go through one another. How can I avoid this and have the counter just add 1 point?

Thanks!

Last edited by vivvicmia (Sept. 9, 2018 15:25:43)

TomasDev
Scratcher
100+ posts

Counter

vivvicmia wrote:

Hello, I am just starting to learn Scratch. I set a counter so that when one sprite touches another one, then the counter should add one point. Both sprites are moving (flying) in opposite directions. But when they touch then the counter goes up by many points since they are actually touching more than once as they go through one another. How can I avoid this and have the counter just add 1 point?

Thanks!
when green flag clicked
forever
if <[COUNTER] > [1]> then
set [counter v] to [1]
end
end
PutneyCat
Scratcher
500+ posts

Counter

Probably a few ways you could do this. Here's one you could try. It should count just once and then wait until the sprites have separated. And then count again when they touch again.

if <touching [the other sprite v] ?> then 
if <(count?) = [yes]> then
change [counter v] by (1)
set [count? v] to [no]
end
else
set [count? v] to [yes]
end

Or, depending on how your other scripts work, a simple
wait (1) secs

might work.
mstone326
Scratcher
1000+ posts

Counter

vivvicmia wrote:

Hello, I am just starting to learn Scratch. I set a counter so that when one sprite touches another one, then the counter should add one point. Both sprites are moving (flying) in opposite directions. But when they touch then the counter goes up by many points since they are actually touching more than once as they go through one another. How can I avoid this and have the counter just add 1 point?

Thanks!
Welcome to Scratch. In your script to add a point, when you change counter by 1, use the wait until not touching whatever Sprite as the next block.

forever
wait until <touching [sprite v] ?>
change [counter v] by (1)
wait until <not <touching [sprite v] ?>>
end

Last edited by mstone326 (Sept. 9, 2018 16:05:09)

vivvicmia
New Scratcher
3 posts

Counter

Thank you this worked!

Powered by DjangoBB