Discuss Scratch

JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

A loop block that basically instead of doing this…
repeat until <touching [idk v] ?>
move (3) steps
end
…does this…
move (3) steps
repeat until <touching [idk v] ?>
move (3) steps
end
so stuff does something at least once (I'd use it so much)
SpyCoderX
Scratcher
1000+ posts

Repeat Once & Until

Definitely useful, but it might confuse people.
BwnnyRxbbit
Scratcher
500+ posts

Repeat Once & Until

I can't really see what this could be used for, can you please expand on it?
rdococ
Scratcher
1000+ posts

Repeat Once & Until

Seems kinda niche. You could ask a question until you get a valid answer:

do {
ask [Save? (y/n)] and wait
} then repeat until <<(answer) = [y]> or <(answer) = [n]>> :: control

But there's a pretty easy workaround, which is more flexible:

ask [Save? (y/n)] and wait
repeat until <<(answer) = [y]> or <(answer) = [n]>>
ask [Invalid answer. Save? (y/n)] and wait
end
mysinginmonsters
Scratcher
100+ posts

Repeat Once & Until

You showed a good workaround in the main post. Just place whatever is inside the loop before it.
JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

BwnnyRxbbit wrote:

I can't really see what this could be used for, can you please expand on it?
In one of my games I'm making, an enemy does an attack, but how it's coded, it moves until it's touching the player, but if you're touching it when it first tries to move, it doesn't move at all and other events refused to work properly because of that.
JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

mysinginmonsters wrote:

You showed a good workaround in the main post. Just place whatever is inside the loop before it.
Sure, that could work in most cenarios, but sometimes, the scripts you want to do this with are a billion blocks long and you're effectively doubling the length.
JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

SpyCoderX wrote:

Definitely useful, but it might confuse people.
What's so confusing about “repeat once and until”? If it is confusing, then it could be something like "repeat once, then until" and if that's still confusing to scratch's target demographic (8 - 16 years) then I guess you have a point. But if students who've been attending school for 3 years still don't understand that, I'd be sort of concerned.

Last edited by JustSomeFellow (Oct. 5, 2024 01:30:19)

Scratch137
Scratcher
1000+ posts

Repeat Once & Until

This is quite similar to a “do while” loop, which runs the code once and then repeats it as long as an expression is true.
Because Scratch's version of the while loop, “repeat until,” is essentially a “while not” loop (it runs while the expression is false), it makes sense that a Scratch version of a do while loop would be inverted in a similar way.

Do while loops can be useful for keeping your code concise, but on Scratch there are workarounds that are quite easy to make, such as the one you showed in your post:

move (3) steps
repeat until <touching [idk v]?>
move (3) steps

If you're concerned with the length of your code, you could use a custom block or a “broadcast and wait” block to avoid having to make the same code twice.

loop code
repeat until <touching [idk v]?>
loop code

define loop code
some long code here::motion
blah blah blah::sound
...

Last edited by Scratch137 (Oct. 5, 2024 01:31:30)

JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

rdococ wrote:

Seems kinda niche. You could ask a question until you get a valid answer:

do {
ask [Save? (y/n)] and wait
} then repeat until <<(answer) = [y]> or <(answer) = [n]>> :: control

But there's a pretty easy workaround, which is more flexible:

ask [Save? (y/n)] and wait
repeat until <<(answer) = [y]> or <(answer) = [n]>>
ask [Invalid answer. Save? (y/n)] and wait
end

As stated in my reply to @mysinginmonsters you're basically doubling the length of your scripts, which makes editing projects very chaotic due to a messy, confusing jumble of code.
JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

Scratch137 wrote:

This is quite similar to a “do while” loop, which runs the code once and then repeats it as long as an expression is true.
Because Scratch's version of the while loop, “repeat until,” is essentially a “while not” loop (it runs while the expression is false), it makes sense that a Scratch version of a do while loop would be inverted in a similar way.

Do while loops can be useful for keeping your code concise, but on Scratch there are workarounds that are quite easy to make, such as the one you showed in your post:

move (3) steps
repeat until <touching [idk v]?>
move (3) steps

If you're concerned with the length of your code, you could use a custom block or a “broadcast and wait” block to avoid having to make the same code twice.

loop code
repeat until <touching [idk v]?>
loop code

define loop code
some long code here::motion
blah blah blah::sound
...
Scratch was made with 8 - 16 year olds in mind and most kids under ~10 might be confused by the whole custom block setup and broadcasting messages. I know in my first project, I had no clue what a broadcast was and would instead detect the volume of other sprites with no sound as an alternative. It took me until my 5th game to use a custom block, let alone broadcasting a message.
mysinginmonsters
Scratcher
100+ posts

Repeat Once & Until

JustSomeFellow wrote:

mysinginmonsters wrote:

You showed a good workaround in the main post. Just place whatever is inside the loop before it.
Sure, that could work in most cenarios, but sometimes, the scripts you want to do this with are a billion blocks long and you're effectively doubling the length.
Just use a custom block so you don't have to repeat the entire code twice
JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

mysinginmonsters wrote:

JustSomeFellow wrote:

mysinginmonsters wrote:

You showed a good workaround in the main post. Just place whatever is inside the loop before it.
Sure, that could work in most cenarios, but sometimes, the scripts you want to do this with are a billion blocks long and you're effectively doubling the length.
Just use a custom block so you don't have to repeat the entire code twice
I re-state my reply to @Scratch137:

“Scratch was made with 8 - 16 year olds in mind and most kids under ~10 might be confused by the whole custom block setup and broadcasting messages. I know in my first project, I had no clue what a broadcast was and would instead detect the volume of other sprites with no sound as an alternative. It took me until my 5th game to use a custom block, let alone broadcasting a message.”
SpyCoderX
Scratcher
1000+ posts

Repeat Once & Until

JustSomeFellow wrote:

I re-state my reply to @Scratch137:

“Scratch was made with 8 - 16 year olds in mind and most kids under ~10 might be confused by the whole custom block setup and broadcasting messages. I know in my first project, I had no clue what a broadcast was and would instead detect the volume of other sprites with no sound as an alternative. It took me until my 5th game to use a custom block, let alone broadcasting a message.”
No one knows what custom blocks do on their first project. Doesn’t mean we add a whole new block because it’s too difficult to learn to use a (super simple) feature.

Also, the people making projects with “billions” of blocks should have already gotten a pretty good understanding of scratch.

(I hope this doesn’t come off as aggressive or rude. I wasn’t trying to write like that)
JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

SpyCoderX wrote:

JustSomeFellow wrote:

I re-state my reply to @Scratch137:

“Scratch was made with 8 - 16 year olds in mind and most kids under ~10 might be confused by the whole custom block setup and broadcasting messages. I know in my first project, I had no clue what a broadcast was and would instead detect the volume of other sprites with no sound as an alternative. It took me until my 5th game to use a custom block, let alone broadcasting a message.”
No one knows what custom blocks do on their first project. Doesn’t mean we add a whole new block because it’s too difficult to learn to use a (super simple) feature.

Also, the people making projects with “billions” of blocks should have already gotten a pretty good understanding of scratch.

(I hope this doesn’t come off as aggressive or rude. I wasn’t trying to write like that)
All I'm really saying is that it'd just be convenient. I mean, why spend time making a whole new custom block when you can spend 2 seconds setting up the one loop block.
scratchcode1_2_3
Scratcher
1000+ posts

Repeat Once & Until

JustSomeFellow wrote:

All I'm really saying is that it'd just be convenient. I mean, why spend time making a whole new custom block when you can spend 2 seconds setting up the one loop block.
it also only takes 2 seconds, just drag thee code to it and
voila! you have a infinitely usable block with short main scripts
mysinginmonsters
Scratcher
100+ posts

Repeat Once & Until

JustSomeFellow wrote:

All I'm really saying is that it'd just be convenient. I mean, why spend time making a whole new custom block when you can spend 2 seconds setting up the one loop block.
Scratch is only giving the basics of programming. The “forever” and “repeat until” blocks are just an introduction to loops. A “do..until” loop isn't really that important, and it adds a layer of confusion for new programmers. Scratch does this with many things, such as leaving out “greater/less than or equal to” blocks for the sake of simplicity.

(Not to mention, a block like this would probably need to introduce a new block structure never seen before, having the expression at the bottom of the C block.)

Last edited by mysinginmonsters (Oct. 12, 2024 03:19:06)

JustSomeFellow
Scratcher
91 posts

Repeat Once & Until

mysinginmonsters wrote:

JustSomeFellow wrote:

All I'm really saying is that it'd just be convenient. I mean, why spend time making a whole new custom block when you can spend 2 seconds setting up the one loop block.
Scratch is only giving the basics of programming. The “forever” and “repeat until” blocks are just an introduction to loops. A “do..until” loop isn't really that important, and it adds a layer of confusion for new programmers. Scratch does this with many things, such as leaving out “greater/less than or equal to” blocks for the sake of simplicity.

(Not to mention, a block like this would probably need to introduce a new block structure never seen before, having the expression at the bottom of the C block.)
If it's confusing, you could just not use it, that's what most new scratchers do. Plus, I and a one of my friends have discussed a block like this and agreed that we've both needed it in a lot of circumstances. You may not think of it as useful, but I do (also, the “days since 2000” block is pretty useless, but we still have it). Also, the “mouse down?” block used to confuse me all the time when I first started scratch. I thought it meant if the mouse was in the lower half of the screen or something like that and the question mark made it look like not even the block itself knew what it was. But over time, I realised what it was, got used to it and now use it all the time and I feel like that's what would happen if this block was introduced. Also, in terms of a new block structure, it wouldn't need that, just put what you want to repeat inside the loop.

Powered by DjangoBB