Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Counter
- vivvicmia
-
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!
Thanks!
Last edited by vivvicmia (Sept. 9, 2018 15:25:43)
- TomasDev
-
100+ 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!
when green flag clicked
forever
if <[COUNTER] > [1]> then
set [counter v] to [1]
end
end
- PutneyCat
-
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.
Or, depending on how your other scripts work, a simple
might work.
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
-
1000+ posts
Counter
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. 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!
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)
- Discussion Forums
- » Help with Scripts
-
» Counter