From Test-Scratch-Wiki
(Redirected from Eng:Cap Blocks)
A Cap block is a block that is designed to stop a script or project from running, cancelling unwanted activity before it can start.
The Cap blocks
There are two Cap blocks, both located in the Control category. They are:
— stops either everything, the script or the other scripts in the sprite. If "stop other scripts in sprite" is selected, it becomes a stack block.
— stops all the scripts that the clone is running and deletes the clone
Shape
As Cap blocks are designed to stop a script or project, their bottom is smooth; no blocks can be placed under them, as there is no need. Other than that, their shape is identical to the Stack block — they still have the notch on the top, so the block can be placed below others.
Making A Cap Block
The coding in the System Browser blockspecs for a cap block is the same as a stack block. To make the bottom smooth, the method at the location Scratch-Blocks >> CommandBlockMorph >> accessing >> isStop
must be edited. Add:
| (selector = #method)
and accept.
Use
The need to stop a script (or all scripts) can be found in several occasions. Some include:
- Disabling a script that will continuously set a variable
- Once a game is completed, all scripts stop
- Deactivating a sprite
An example follows:
set [Letter v] to [0] repeat (length of (answer)) change [Letter v] by (1) if <(letter (Letter) of (answer)) = [z]> then stop [this script v] end end
Note how the Cap block (Stop ()) is used — if the selected letter is "z", the script stops.