() is a custom block, or procedure, all of which are Stack blocks in the More Blocks palette. A version of it is created for every custom block, much like with the variable block. Custom blocks are usually used to make long or frequently repeated scripts in projects accessible in a single block.
A procedure is created by clicking "Make a block" in the More Blocks palette. This creates a dialogue, where the block can be named, and arguments defined. (These can be edited via the context menu.) Clicking OK will create a Define () block with the procedure inside. Blocks can then be stacked beneath it. When the procedure is run, it will run the blocks under the Define hat.
define jump repeat (20) change y by (1) //upward motion end repeat (20) change y by (-1) //downward motion end
when gf clicked pen down repeat (40) draw :: custom define draw repeat (4) change [i v] by (0.2) move ((i) * (5)) steps turn cw ((120) + ((i) / (20))) degrees set pen color to (i) set pen shade to (i) end
- Making a sprite visually pointing in direction "A" but moving in direction "B"
define point in direction (A) move direction (B) point in direction (B) //since the procedure is atomic, this will go unseen move (3) steps //motion is in the correct direction point in direction (A)
An example use of booleans in custom blocks.
- When Boolean in true, script activates if the block is put in a forever loop
define say [string] when <boolean> if <boolean> then: say (string) end
- Main article: List of Block Workarounds
broadcast [procedure v] and wait when I receive [procedure v] move (10) steps
This can still be done in Scratch 2.0. Backdrop events can also be used.
This is not a perfect workaround, as procedures are recursive, while broadcasts are just tail-recursive. Furthermore, broadcast scripts cannot run without screen refresh, which is one benefit of using custom blocks. Inputs, while possible, require separate variables.
BugsIt is possible to insert inputs other than numbers, strings, and booleans in custom blocks.
Blocks with boolean inputs will not respond to changes in the boolean's state.
Using the "Run without screen refresh" option may cause audible errors in sounds.