Discuss Scratch

DontEatSand
Scratcher
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
Scratcher
500+ posts

"stronger" while loops

Loops that stop the entire project can be easily worked around:
repeat until <...>
...
end
stop [all v]
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.
lovecodeabc
Scratcher
1000+ posts

"stronger" while loops

repeat until <not <...>>

end
DontEatSand
Scratcher
12 posts

"stronger" while loops

PhiPhenomenon wrote:

Loops that stop the entire project can be easily worked around:
repeat until <...>
...
end
stop [all v]
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.
thanks, i'll try that out
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
Scratcher
12 posts

"stronger" while loops

lovecodeabc wrote:

repeat until <not <...>>

end
did you even read the post? this was the block i was complaining about!
PhiPhenomenon
Scratcher
500+ posts

"stronger" while loops

DontEatSand wrote:

PhiPhenomenon wrote:

Loops that stop the entire project can be easily worked around:
repeat until <...>
...
end
stop [all v]
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.
thanks, i'll try that out
edit: it just stops the entire thing. this isn't what i'm looking for
You said in the OP that you wanted a loop that terminated the entire project once to finishes.

DontEatSand wrote:

only the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
DontEatSand
Scratcher
12 posts

"stronger" while loops

PhiPhenomenon wrote:

DontEatSand wrote:

PhiPhenomenon wrote:

Loops that stop the entire project can be easily worked around:
repeat until <...>
...
end
stop [all v]
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.
thanks, i'll try that out
edit: it just stops the entire thing. this isn't what i'm looking for
You said in the OP that you wanted a loop that terminated the entire project once to finishes.

DontEatSand wrote:

only the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
sorry if i worded it wrong, should i link a project so you see what i mean?
PhiPhenomenon
Scratcher
500+ posts

"stronger" while loops

DontEatSand wrote:

PhiPhenomenon wrote:

DontEatSand wrote:

PhiPhenomenon wrote:

Loops that stop the entire project can be easily worked around:
repeat until <...>
...
end
stop [all v]
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.
thanks, i'll try that out
edit: it just stops the entire thing. this isn't what i'm looking for
You said in the OP that you wanted a loop that terminated the entire project once to finishes.

DontEatSand wrote:

only the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
sorry if i worded it wrong, should i link a project so you see what i mean?
Sure, if that helps. But it'd be easier to understand if it's been worded right.
DontEatSand
Scratcher
12 posts

"stronger" while loops

PhiPhenomenon wrote:

DontEatSand wrote:

PhiPhenomenon wrote:

DontEatSand wrote:

PhiPhenomenon wrote:

Loops that stop the entire project can be easily worked around:
repeat until <...>
...
end
stop [all v]
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.
thanks, i'll try that out
edit: it just stops the entire thing. this isn't what i'm looking for
You said in the OP that you wanted a loop that terminated the entire project once to finishes.

DontEatSand wrote:

only the sprite's code stops to continue the loop until it's satisfied, but the entire project will keep going.
sorry if i worded it wrong, should i link a project so you see what i mean?
Sure, if that helps. But it'd be easier to understand if it's been worded right.
https://scratch.mit.edu/projects/810561960/
here's what i meant
PhiPhenomenon
Scratcher
500+ posts

"stronger" while loops

DontEatSand wrote:

https://scratch.mit.edu/projects/810561960/
here's what i meant
How does this explain anything?
DontEatSand
Scratcher
12 posts

"stronger" while loops

PhiPhenomenon wrote:

DontEatSand wrote:

https://scratch.mit.edu/projects/810561960/
here's what i meant
How does this explain anything?
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 satisfied

Last edited by DontEatSand (Feb. 27, 2023 17:22:28)

DontEatSand
Scratcher
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
Scratcher
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
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
Scratcher
1000+ posts

"stronger" while loops

// [x] Run without screen refresh
define instant while
repeat until <not <condition :: grey>>
move (10) steps
end

when gf clicked
instant while :: custom
I 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.
YtArie5
Scratcher
1000+ posts

"stronger" while loops

I mean you could use broadcasts and “stop other scripts in sprite” but that's quite tedious.
imfh
Scratcher
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/

Last edited by imfh (Feb. 27, 2023 20:24:23)

DontEatSand
Scratcher
12 posts

"stronger" while loops

imfh wrote:

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/
wait, these actually exist? blocks that don't appear in the pallet?
tested the block out, yeah, it's not useful at all

Last edited by DontEatSand (Feb. 28, 2023 17:13:57)

imfh
Scratcher
1000+ posts

"stronger" while loops

DontEatSand wrote:

imfh wrote:

-snip-
wait, these actually exist? blocks that don't appear in the pallet?
tested the block out, yeah, it's not useful at all
Yes, it is one of the experimental blocks and was never removed.
cookieclickerer33
Scratcher
1000+ posts

"stronger" while loops

DontEatSand wrote:

imfh wrote:

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/
wait, these actually exist? blocks that don't appear in the pallet?
tested the block out, yeah, it's not useful at all
It’s literally a while loop, idk what you are dissipointed about

Powered by DjangoBB