- "Stop all" redirects here. For this block in Scratch 1.4, see Stop All (block).
- "Stop this script" redirects here. For this block in Scratch 1.4, see Stop Script (block).
Stop () | |
stop [ v] | |
Category | Control |
Type | Cap/Stack (changes depending on argument) |
Introduced in | 2.0 |
The Stop () block is a Control block. Depending on the option chosen in the dropdown, it is either a Cap block ("all" or "this script"), or a Stack block ("other scripts in sprite"). It is the only block that changes its shape. It was added in Scratch 2.0 to replace the Stop All and Stop Script blocks, and also to add the functionality of stopping other scripts in a sprite. If there are blocks below it and it is a stack block, the other options in the dropdown will be missing.
Options
- all - stops all scripts in the entire project. This has the same behavior as clicking the stop sign
- this script - stops the script the block is in. When using this mode inside of a custom block, it will resume the script the custom block was run from.
- other scripts in sprite - stops all scripts in the sprite this block is in except the script the block is running on
Note: | this mode turns the block from a cap block to a stack block |
Example Uses
stop [other scripts in sprite v]::stack
This block can be used in some of the following ways:
- Ending a project once all the actions are carried out
when I receive [end v] say [That's all folks!] for (2) seconds stop [all v]
- Stopping a project — when all lives are lost, for example
when gf clicked forever if < (lives) = [0] > then stop [all v] end
- Disabling controls
when gf clicked forever if << key (up arrow v) pressed? > and < (jumping) = [0] > > then set [delta-y v] to [5] end if < (level) = [7] > then stop [this script v] end
- Disabling a sprite
when gf clicked forever if < (x position) > [100] > then stop [other scripts in sprite v] stop [this script v] end
- Only performing an action a certain amount of times, and then stopping
when gf clicked set [x v] to [0] forever if < (x) = [5] > then stop [this script v] end move (10) steps if on edge, bounce change [x v] by (1)
- Implementing recursion-based procedures (as an end condition)
define factorial (n) set [result v] to (n) set [counter v] to ((n) - [1]) forever if < (counter) > [1] > then set [result v] to ((result) * (counter)) change [counter v] by [-1] else stop [this script v] end end when gf clicked factorial (5) say (result) for [2] seconds // The main script will not stop because the "stop this script" block is in the "factorial" block, and it will not interfere with the main script.