Break cycle in Scratch?

How to make an intermittent loop in Scratch? I am using Scratch 2.0 and cannot find a good way to make the loop intermittent from within the loop itself.

+6
source share
6 answers

Denial of responsibility:

There is no perfect way to do this. If you can stand this true fact, then feel free to continue.


There are several ways to do this.

With repeat until

The first and simplest of them follows:

scratchblocks

But this is not technically part of the script - it simply repeats until some value returns true.

With custom block ( stop this script )

To do this inside the script, you need to use a hidden little trick with custom blocks.

Create the custom block you want, but perhaps along the lines of the "breakable loop". Inside this, create this script:

scratchblocks

Using the stop script , we exit the script that is currently running, which, according to Scratch, is a custom block.

See the result! (like notepads)

With broadcast and wait

You can also use the broadcast and wait method, very similar to the above:

scratchblocks

Although I strongly recommend that you do not use this method as if other sprites had intermittent loops, you will need to rename them, which can be tedious after using many loops in many sprites!


(Note that this error was fixed in the editor version 442 of the editor, and this procedure is no longer applied.)

Help! My project is already falling off!

As @foi noted , if your code should be running inside a frame that you probably checked , run without refreshing the screen . Unfortunately, due to an error in the Scratch player, this causes the program to crash significantly after the stop this script block has been activated. How can you handle this?

It follows the same principle that you use when running without a custom screen update block inside the forever loop - the loop does not use screen refresh while working inside, which allows instant animation regardless of using turbo mode .

Here's an example - the image is too long to be embedded, so see here .

+8
source

You can make a variable inside or outside repeat and make your script like this:

 repeat until [[my variable] = [eg: 1]] your code your code your code your code end of repeat until 
+2
source

For the "repeat until" block, the easiest way is to "or" your normal to a state with an interrupt condition until then.

By adding the increment loop counter variable in the loop, you can use “repeat up” to replicate the function of the “repeat n times” block

Using the repeat to block with only an interrupt condition, you get the equivalent of the forever block

If you need another script / sprite to cause a break, then the public variable will allow you to break the loop from anywhere and allow one condition to break the loops for different sprites.

I would post a block image, but this is my first answer, and the site will not let me!

luck

+1
source

You can use these several ways to do this ...

  • conditional loop

  • stop this script

  • if then else, do not put anything in the else section

I would prefer to use the first method, since it requires fewer blocks, and for the first method you can still add code that will be executed after the loop stops running.

+1
source

You can make it repeat x times or make it have a specific point where it stops, for example, changing another variable.

Otherwise, I don’t think there is wat to do this.

0
source

Use repeat until block . Then insert the equal block or something else into the logical part. Then inside this repeat until block, paste stop this script block.

Hope this helps: D

-1
source

All Articles