Revision as of 18:38, 15 July 2014 by Djdolphin (talk | contribs) (Fixed it up to standards)

Custom blocks allow for one to make his or her own programming blocks. Using custom blocks, large, similar scripts can be combined into one reusable block. In some other programming languages, custom blocks are called "procedures", "functions", or "methods".

A "jump" custom block.
A "jump" custom block with number input.
Recursive factorial procedure — Scratch 2.0 alpha.

Custom Blocks in Scratch

Custom blocks are found in the "More Blocks" palette.[1] The palette starts off empty and just shows a "Make a Block" button (similar to the "Make a Variable/List" buttons in the data palette). For each Define block (whether from the make a block button, or by dragging in from the backpack or another sprite), a custom block is shown in the palette. The custom block is only available to the sprite that has the Define block.[2]

Custom blocks can only be stack blocks, not reporters or booleans (though they may be added in the future).[3] They support recursion, so blocks can call themselves (This doesn't stop the current block executing, unlike broadcasts). This allows for things like creating fractals and finding the factorial of a number.

Creating a Custom Block

To create a custom block, open the "More Blocks" category and press the "Make a Block" button. A new block menu will open, where you can name your custom block. By pressing "Options", you can add string, number, and boolean inputs. You can also add more label text to the block, or make it run without screen refresh. After naming and adding arguments, a Define block is created. A custom block's settings can later be changed by right-clicking on its Define block or the custom block itself and selecting "edit". You can define what your custom block does by snapping a script to its Define block, as shown below.

spin right (360) degrees

define spin right (amount) degrees
repeat (amount)
turn right (1) degrees

Procedures in BYOB/Snap!

Snap!, previously called BYOB (Build Your Own Blocks), is a Scratch modification that allows procedures. Snap!'s procedures allow all 3 types of blocks, with arguments, and also recursion.

See Also