Discuss Scratch

Miastonished
Scratcher
100+ posts

'Break' Block

This is a new block I want added.
Example:
Script :: hat events
repeat (1000)
if <key[space v] pressed> then
break [loop 1 v] :: control //The block
end
move (10) steps
end
...

When the code runs it repeats 1000 times. It will stop when you press space or it will move until the loop finishes.

Last edited by Miastonished (Aug. 10, 2017 05:44:50)

WolfCat67
Scratcher
1000+ posts

'Break' Block

How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?
Miastonished
Scratcher
100+ posts

'Break' Block

WolfCat67 wrote:

How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?

Maybe:

Break [Loop v] :: control

The loop part being like a colour picker. Instead for blocks.
WolfCat67
Scratcher
1000+ posts

'Break' Block

will803 wrote:

WolfCat67 wrote:

How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?

Maybe:

Break [Loop v] :: control

The loop part being like a colour picker. Instead for blocks.
So… Every loop would need to be assigned a kind of ID of sorts, and when clicking on it, you'd be able to choose which one?
I don't know, seems like quite a lot of work.
Miastonished
Scratcher
100+ posts

'Break' Block

WolfCat67 wrote:

will803 wrote:

WolfCat67 wrote:

How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?

Maybe:

Break [Loop v] :: control

The loop part being like a colour picker. Instead for blocks.
So… Every loop would need to be assigned a kind of ID of sorts, and when clicking on it, you'd be able to choose which one?
I don't know, seems like quite a lot of work.
Just something simple like ‘Loop 7’.
kenny2scratch
Scratcher
500+ posts

'Break' Block

WolfCat67 wrote:

How will it know which loop to “break”, though? I mean, it makes sense partially, but in reality, how would it determine whether to break the “if <> then” statement or the repeat?
If statements aren't loops


In the example script, that would break the repeat loop and stop. If the only purpose of that script after breaking is to stop, you can do
script :: events hat
repeat (1000)
if <key [space v] pressed?> then
stop [this script v] // you can just stop the script inside without having to break
end
move (10) steps
end
That will stop the script when you press space.
I do, however, support this block for other reasons (namely, there are certain scripts that do something after breaking).

My main concern with the block would be, again, how easy it is to understand. New Scratchers probably wouldn't get the concept… but otherwise, support.
Charles12310
Scratcher
1000+ posts

'Break' Block

What is the purpose of this break block?
Miastonished
Scratcher
100+ posts

'Break' Block

Charles12310 wrote:

What is the purpose of this break block?
To get out of a loop.
Charles12310
Scratcher
1000+ posts

'Break' Block

Alternative:

when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end

When the space key is pressed, it stops the loop script.
Miastonished
Scratcher
100+ posts

'Break' Block

Charles12310 wrote:

Alternative:

when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end

When the space key is pressed, it stops the loop script.
Example script:

when green flag clicked
repeat (1000) // Randomly Long Intro
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end
Game stuff... :: grey // Game stuff
duckboycool
Scratcher
1000+ posts

'Break' Block

The repeat until block exists for a reason.

set [loops v] to [0]
repeat until <<...> or <(loops) > [999]>>
...
change [loops v] by (1)
end
Sheep_maker
Scratcher
1000+ posts

'Break' Block

Based off duckboycool's workaround, for a general break block:
set [break v] to [no]
repeat until <<...>or<(break)=[yes]>>
if (...::grey) then // example script
set [break v] to [yes]
end
end
however this workaround won't stop the rest of the loop's scripts.

Maybe
stop [this loop v]
since programming language terms are hard to translate to other languages?
walkcycle
Scratcher
500+ posts

'Break' Block

when green flag clicked
set [break v] to [no]
broadcast [loop v]

when I receive [loop v]
if < (break) = [no] > then
repeat until <...>
end
end

define break
set [break v] to [yes]
broadcast [loop v]

break // should arbitrarily break the loop or my scratch-fu is too rusty

WolfCat67
Scratcher
1000+ posts

'Break' Block

Sheep_maker wrote:

Based off duckboycool's workaround, for a general break block:
set [break v] to [no]
set [loops v] to [0]
repeat until <<(loops) = [999]>or<(break)=[yes]>>
if (...::grey) then // example script
set [break v] to [yes]
end
change [loops v] by (1)
end
however this workaround won't stop the rest of the loop's scripts.
The repeat until is the loop in the example. I've added the loop variable itself to demonstrate it above.
Scratcher1002
Scratcher
1000+ posts

'Break' Block

How about:
repeat (1000) {
if <key [space v] pressed?> then
break [grandparent v] :: control

move (10) steps
} :: control

break [parent v] :: control // Stops the c-block the script is in
break [grandparent v] :: control // Stops the parent of the c-block it's in.

Last edited by Scratcher1002 (July 4, 2017 16:14:26)

walkcycle
Scratcher
500+ posts

'Break' Block

^ That would be like this thread with workarounds.
Charles12310
Scratcher
1000+ posts

'Break' Block

Charles12310 wrote:

Workaround:

when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end

When the space key is pressed, it stops the loop script.
The way this workaround works is that when an action happens, the script is stopped. However, if you attach other blocks to outside of the repeat script (what I mean is it isn't in the repeat block, it's outside of it, but it still part of the full script).

This example is the opposite:

when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
broadcast [continue v]
stop [this script v]
end
move (10) steps
end

when I receive [continue v]
...

The broadcast button starts another script before breaking the looping script. It's not a “boardcast () and wait” block, so the stop block happens right after the broadcast block is activated.

When the broadcast is received other scripts happen.

I recommend to put a wait block in the “when I receive block” in-case the loop script doesn't stop quickly.

Last edited by Charles12310 (July 5, 2017 02:04:22)

LionHeart70
Scratcher
1000+ posts

'Break' Block

How about use this block:
stop [this script]
Miastonished
Scratcher
100+ posts

'Break' Block

LionHeart70 wrote:

How about use this block:
stop [this script]
Have you seen the example script?
Charles12310
Scratcher
1000+ posts

'Break' Block

will803 wrote:

LionHeart70 wrote:

How about use this block:
stop [this script]
Have you seen the example script?
You mean this one:

Charles12310 wrote:

Charles12310 wrote:

Workaround:

when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
stop [this script v]
end
move (10) steps
end

When the space key is pressed, it stops the loop script.
The way this workaround works is that when an action happens, the script is stopped. However, if you attach other blocks to outside of the repeat script (what I mean is it isn't in the repeat block, it's outside of it, but it still part of the full script).

This example is the opposite:

when green flag clicked
repeat (1000)
if <key [space v] pressed?> then
broadcast [continue v]
stop [this script v]
end
move (10) steps
end

when I receive [continue v]
...

The broadcast button starts another script before breaking the looping script. It's not a “boardcast () and wait” block, so the stop block happens right after the broadcast block is activated.

When the broadcast is received other scripts happen.

I recommend to put a wait block in the “when I receive block” in-case the loop script doesn't stop quickly.

Powered by DjangoBB