This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective. For information on the feature that replaced this one, see Stop () (block). |
Stop Script | |
stop script:: control | |
Category | Control |
Type | Cap |
Introduced in | 1.0 |
Removed in | v121[citation needed] (2.0 alpha) |
The Stop Script block was a Control block and a Cap block. The block would deactivate its script, stopping it completely. This block worked similar to the Stop All block, except that it was confined to its script and did not deactivate all scripts in the project.
Before version 1.2, the block was a stack block. Before 1.0, this block was called Done, along with another block with the same function in 0.1 and 0.2. This block became obsolete in an alpha release of Scratch 2.0 with the introduction of the Stop () block.
Workaround
- Main article: List of Block Workarounds
The "Stop Script" was most often used to stop loops (especially Forever and Forever If () loops). A common workaround is to use a Repeat Until () loop instead.
repeat until <. . .::grey> . . . end
However, such a workaround is not perfect. The primary advantage of the "Stop Script" is its ability to be used throughout the loop. For loops that are lengthy, one often wants to stop the script as quickly as possible, rather than waiting for the script to loop back through the conditional. This is easily done with the "Stop Script" block within an If () Then block. For instance, the following script has a faster "reaction time" to an event that demands the script be stopped than the one above.
forever . . . if <. . .::grey> { stop script:: control }:: control . . . if <. . .::grey> { stop script:: control }:: control
The following workaround pauses the script at one point forever, rather than stopping the script, but can still be used to prevent code from being activated.
when gf clicked:: control . . . wait until <[1] = [0]> // the condition will never be met, thus making the script wait forever
Or for a simple one-block method in 2.0 and 3.0:
stop [this script v]
Example Uses
As this block will stop its script, it is widely used when an action performed by a script must cease. Some common uses:
- Disabling controls
forever if <(ammunition) < [1]> { set [active v] to [0] stop script:: control } else { set [active v] to [1] }:: control
- Only performing an action once, and then stopping
forever if <(loss) = [1]> { broadcast [failure v]:: control stop script:: control } @loopArrow:: control cap
- Depending on a variable, if an action is performed or the script canceled
when I receive [Show v]:: control switch to costume [costume1 v]:: looks if <(allow) = [1]> then go to x: (0) y: (0) else stop script:: control end broadcast [Ready! v]:: control