Discuss Scratch
- Discussion Forums
- » Suggestions
- » "stronger" while loops
- DontEatSand
-
12 posts
"stronger" while loops
i've been noticing that the “repeat until” loop is scratch's equivalent of a while loop, but i really don't like it because it's not really an actual while loop. only the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going. this is a lot more of a problem than you probably think it is.
Last edited by DontEatSand (Feb. 27, 2023 15:32:23)
- PhiPhenomenon
-
500+ posts
"stronger" while loops
Loops that stop the entire project can be easily worked around:
repeat until <...>Actual while loops won't stop the project either. Because Scratch can run many scripts in parallel, the while loop ending would only stop one thread.
...
end
stop [all v]
- DontEatSand
-
12 posts
"stronger" while loops
thanks, i'll try that out Loops that stop the entire project can be easily worked around:repeat until <...>Actual while loops won't stop the project either. Because Scratch can run many scripts in parallel, the while loop ending would only stop one thread.
...
end
stop [all v]
edit: it just stops the entire thing forever. this isn't what i'm looking for, i only want the project to stop while the loop is being fufilled, not forever
Last edited by DontEatSand (Feb. 27, 2023 15:39:17)
- DontEatSand
-
12 posts
"stronger" while loops
did you even read the post? this was the block i was complaining about!repeat until <not <...>>
end
- PhiPhenomenon
-
500+ posts
"stronger" while loops
You said in the OP that you wanted a loop that terminated the entire project once to finishes.thanks, i'll try that out Loops that stop the entire project can be easily worked around:repeat until <...>Actual while loops won't stop the project either. Because Scratch can run many scripts in parallel, the while loop ending would only stop one thread.
...
end
stop [all v]
edit: it just stops the entire thing. this isn't what i'm looking for
only the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
- DontEatSand
-
12 posts
"stronger" while loops
sorry if i worded it wrong, should i link a project so you see what i mean?You said in the OP that you wanted a loop that terminated the entire project once to finishes.thanks, i'll try that out Loops that stop the entire project can be easily worked around:repeat until <...>Actual while loops won't stop the project either. Because Scratch can run many scripts in parallel, the while loop ending would only stop one thread.
...
end
stop [all v]
edit: it just stops the entire thing. this isn't what i'm looking foronly the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
- PhiPhenomenon
-
500+ posts
"stronger" while loops
Sure, if that helps. But it'd be easier to understand if it's been worded right.sorry if i worded it wrong, should i link a project so you see what i mean?You said in the OP that you wanted a loop that terminated the entire project once to finishes.thanks, i'll try that out Loops that stop the entire project can be easily worked around:repeat until <...>Actual while loops won't stop the project either. Because Scratch can run many scripts in parallel, the while loop ending would only stop one thread.
...
end
stop [all v]
edit: it just stops the entire thing. this isn't what i'm looking foronly the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
- DontEatSand
-
12 posts
"stronger" while loops
https://scratch.mit.edu/projects/810561960/Sure, if that helps. But it'd be easier to understand if it's been worded right.sorry if i worded it wrong, should i link a project so you see what i mean?You said in the OP that you wanted a loop that terminated the entire project once to finishes.thanks, i'll try that out Loops that stop the entire project can be easily worked around:repeat until <...>Actual while loops won't stop the project either. Because Scratch can run many scripts in parallel, the while loop ending would only stop one thread.
...
end
stop [all v]
edit: it just stops the entire thing. this isn't what i'm looking foronly the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
here's what i meant
- PhiPhenomenon
-
500+ posts
"stronger" while loops
https://scratch.mit.edu/projects/810561960/How does this explain anything?
here's what i meant
- DontEatSand
-
12 posts
"stronger" while loops
if the repeat until loop was an actual while loop, the scratch cat would have instantly ended up on the right, and the cross wouldn't really start spinning until the cat's loop was satisfiedhttps://scratch.mit.edu/projects/810561960/How does this explain anything?
here's what i meant
Last edited by DontEatSand (Feb. 27, 2023 17:22:28)
- DontEatSand
-
12 posts
"stronger" while loops
actually, i think i know a (really tedious) workaround for this, and it's to have just one forever loop do basically everything. it's probably still going to have its limitations, but hey, it's there. if the forever loop wants a sprite to do something, since a sprite can't directly manipulate other sprites, it will broadcast a message to that sprite, and the sprite complies with what that broadcast “means”.
Last edited by DontEatSand (Feb. 27, 2023 17:49:52)
- cookieclickerer33
-
1000+ posts
"stronger" while loops
The block exists in scratch it’s just hidden in the pallet normally
https://scratch.mit.edu/projects/810590445/
It’s also fully functional
From what I understand you can do
https://scratch.mit.edu/projects/810590445/
It’s also fully functional
From what I understand you can do
Broadcast [stop all but this script v]
When I receive [stop all but this script v]
Stop [other scripts in this sprite v] //put in every sprite apart from the current one
//then do
Broadcast [stop all but this script v]
Stop [other scripts in this sprite v]::stack
While <>{
Do code ::grey
}::control
Stop [this script v]::cap
Last edited by cookieclickerer33 (Feb. 27, 2023 17:57:41)
- lolecksdeehaha
-
1000+ posts
"stronger" while loops
// [x] Run without screen refreshI agree that it's tedious to create a bunch of blocks that do this, but it works. A problem with this being default behavior is that it can cause some projects to crash instantly if the condition is never satisfied in the loop; for a children's programming app, it may not be understood and therefore it's better to act like a normal forever loop when it hasn't been satisfied.
define instant while
repeat until <not <condition :: grey>>
move (10) steps
end
when gf clicked
instant while :: custom
- YtArie5
-
1000+ posts
"stronger" while loops
I mean you could use broadcasts and “stop other scripts in sprite” but that's quite tedious.
- imfh
-
1000+ posts
"stronger" while loops
Scratch is asynchronous, which means multiple scripts can run at the same time. If you want to prevent other scripts from running, you’ll need to use the “run without screen refresh” option of custom blocks, like suggested above.
When a run without screen refresh block runs, nothing else runs until the block finishes. The screen also doesn’t update, which means whatever you put in the block should finish quickly. If you put something in the block which takes longer than 0.5 seconds, other stuff will be allowed to run to prevent Scratch from crashing.
If custom blocks don’t work for you, I would make a topic in Help With Script describing what you are trying to do. Someone will probably be able to point you in the right direction.
Like mentioned above, Scratch actually has while loops. They act exactly like repeat until loops with respect to stuff running at the same time though. Since they aren’t really useful, they are not in the block pallet. https://scratch.mit.edu/projects/49037046/editor/
When a run without screen refresh block runs, nothing else runs until the block finishes. The screen also doesn’t update, which means whatever you put in the block should finish quickly. If you put something in the block which takes longer than 0.5 seconds, other stuff will be allowed to run to prevent Scratch from crashing.
If custom blocks don’t work for you, I would make a topic in Help With Script describing what you are trying to do. Someone will probably be able to point you in the right direction.
Like mentioned above, Scratch actually has while loops. They act exactly like repeat until loops with respect to stuff running at the same time though. Since they aren’t really useful, they are not in the block pallet. https://scratch.mit.edu/projects/49037046/editor/
Last edited by imfh (Feb. 27, 2023 20:24:23)
- DontEatSand
-
12 posts
"stronger" while loops
wait, these actually exist? blocks that don't appear in the pallet? Scratch is asynchronous, which means multiple scripts can run at the same time. If you want to prevent other scripts from running, you’ll need to use the “run without screen refresh” option of custom blocks, like suggested above.
When a run without screen refresh block runs, nothing else runs until the block finishes. The screen also doesn’t update, which means whatever you put in the block should finish quickly. If you put something in the block which takes longer than 0.5 seconds, other stuff will be allowed to run to prevent Scratch from crashing.
If custom blocks don’t work for you, I would make a topic in Help With Script describing what you are trying to do. Someone will probably be able to point you in the right direction.
Like mentioned above, Scratch actually has while loops. They act exactly like repeat until loops with respect to stuff running at the same time though. Since they aren’t really useful, they are not in the block pallet. https://scratch.mit.edu/projects/49037046/editor/
tested the block out, yeah, it's not useful at all
Last edited by DontEatSand (Feb. 28, 2023 17:13:57)
- imfh
-
1000+ posts
"stronger" while loops
Yes, it is one of the experimental blocks and was never removed.wait, these actually exist? blocks that don't appear in the pallet? -snip-
tested the block out, yeah, it's not useful at all
- cookieclickerer33
-
1000+ posts
"stronger" while loops
It’s literally a while loop, idk what you are dissipointed aboutwait, these actually exist? blocks that don't appear in the pallet? Scratch is asynchronous, which means multiple scripts can run at the same time. If you want to prevent other scripts from running, you’ll need to use the “run without screen refresh” option of custom blocks, like suggested above.
When a run without screen refresh block runs, nothing else runs until the block finishes. The screen also doesn’t update, which means whatever you put in the block should finish quickly. If you put something in the block which takes longer than 0.5 seconds, other stuff will be allowed to run to prevent Scratch from crashing.
If custom blocks don’t work for you, I would make a topic in Help With Script describing what you are trying to do. Someone will probably be able to point you in the right direction.
Like mentioned above, Scratch actually has while loops. They act exactly like repeat until loops with respect to stuff running at the same time though. Since they aren’t really useful, they are not in the block pallet. https://scratch.mit.edu/projects/49037046/editor/
tested the block out, yeah, it's not useful at all
- Discussion Forums
- » Suggestions
-
» "stronger" while loops