Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » loop with condition repeated several times
- Lids432
-
Scratcher
6 posts
loop with condition repeated several times
I have two sprites. I would like to change the time necessary for one of the sprites to move down the stage on condition that the other sprite untouches it several times. I am a bit stuck here. I have tried to use negative condition and created two different variables. I will appreciate any help.
- JustTbear
-
Scratcher
100+ posts
loop with condition repeated several times
Hmmm…
Do you mean something like “if I'm touching Sprite1, get slower”?
Do you mean something like “if I'm touching Sprite1, get slower”?
- deck26
-
Scratcher
1000+ posts
loop with condition repeated several times
What does ‘untouches it several times’ mean??
Sharing what you have would make it easier to understand.
Sharing what you have would make it easier to understand.
- Oumuamua
-
Scratcher
1000+ posts
loop with condition repeated several times
I have two sprites. I would like to change the time necessary for one of the sprites to move down the stage on condition that the other sprite untouches it several times. I am a bit stuck here. I have tried to use negative condition and created two different variables. I will appreciate any help.
Something like this?
repeat until <(y position) < [-175]>
if <not <touching [ v] ?>> then
change y by (-5)
end
end
- Lids432
-
Scratcher
6 posts
loop with condition repeated several times
Sorry, I mean, I need to change the time necessary for one sprite to get across the stage when the other sprite managed to avoid it several times. I am not sure how to repeat the condition two times before it changes the speed of travel in seconds. I need to repeat the condition of “not touching” other sprite 2 times before changing the time required to travel across the screen.
- mrtbts_test
-
Scratcher
17 posts
loop with condition repeated several times
repeat (2)is this correct
if <not <touching [ v] ?>> then
end
end
- Lids432
-
Scratcher
6 posts
loop with condition repeated several times
https://scratch.mit.edu/projects/397186356/
This is my project.
This is my project.
- Lids432
-
Scratcher
6 posts
loop with condition repeated several times
Hi, mrbts_test,
For my script, the condition need to be satisfied two times, before the speed changes. If I action the script below. It will repeat everything inside that “repeat 2 block”, icluding the change of speed, it will repeat the change of speed 2 times. I think, I need to use something else here. I would like to repeat the “not touching” condition twice, and then change the speed once. And I am not sure how to do it.
For my script, the condition need to be satisfied two times, before the speed changes. If I action the script below. It will repeat everything inside that “repeat 2 block”, icluding the change of speed, it will repeat the change of speed 2 times. I think, I need to use something else here. I would like to repeat the “not touching” condition twice, and then change the speed once. And I am not sure how to do it.
repeat (2)is this correct
if <not <touching [ v] ?>> then
end
end
Last edited by Lids432 (May 20, 2020 07:19:03)
- Lids432
-
Scratcher
6 posts
loop with condition repeated several times
I do not think it is going to work this way. Both sprites are moving, and the condition of changing speed of one sprite depends on the other's ability to avoid it. It should be somethimg like:
Repeat until the other sprite is avoided 2 times
If not touching 2 times,
Then change speed by 5.
I am not sure how to repeat the same condition 2 times and change the speed only once.
Something like this?
Something like this?
Repeat until the other sprite is avoided 2 times
If not touching 2 times,
Then change speed by 5.
I am not sure how to repeat the same condition 2 times and change the speed only once.
Something like this?
Something like this?
repeat until <(y position) < [-175]>
if <not <touching [ v] ?>> then
change y by (-5)
end
end
Last edited by Lids432 (May 20, 2020 07:30:53)
- deck26
-
Scratcher
1000+ posts
loop with condition repeated several times
So the dragonfly is moving to a random position in a loop using glide. You'd actually have more control using move n steps in a loop rather than glide but never mind that just now.
It sounds like you want to know if the dragonfly completes two such moves without being caught. So something like this should work.
It sounds like you want to know if the dragonfly completes two such moves without being caught. So something like this should work.
set [caught v] to [0]The second loop then sets caught to 1 when touching the bat. It doesn't need to do anything else.
set [count v] to [0]
forever
go to x: (59) y: (92)
glide (Speed) secs to [random position v]
if <(caught) = [0]> then // successful move
change [count v] by [1]
if <(count) = [2]> then
code for when two successful moves
set [count v] to [0] // reset count
end
else
set [count v] to [0] // was caught so restart count
end
set [caught v] to [0] // reset caught for next move
end
Last edited by deck26 (May 20, 2020 07:53:45)
- Lids432
-
Scratcher
6 posts
loop with condition repeated several times
Thnak you, I will try it now.
So the dragonfly is moving to a random position in a loop using glide. You'd actually have more control using move n steps in a loop rather than glide but never mind that just now.
It sounds like you want to know if the dragonfly completes two such moves without being caught. So something like this should work.set [caught v] to [0]The second loop then sets caught to 1 when touching the bat. It doesn't need to do anything else.
set [count v] to [0]
forever
go to x: (59) y: (92)
glide (Speed) secs to [random position v]
if <(caught) = [0]> then // successful move
change [count v] by [1]
if <(count) = [2]> then
code for when two successful moves
set [count v] to [0] // reset count
end
else
set [count v] to [0] // was caught so restart count
end
set [caught v] to [0] // reset caught for next move
end
- Discussion Forums
- » Help with Scripts
-
» loop with condition repeated several times