(Redirected from Custom Blocks)

"Custom Block" redirects here. For the block itself, see () (Custom block).
SandCastleIcon.png This page has links to websites or programs not trusted by Scratch or hosted by Wikipedia. Remember to stay safe while using the Internet, as we can't guarantee the safety of other websites.
define custom block
The define block in Scratch 3.0.
My Blocks (known as More Blocks in Scratch 2.0) is one of the ten categories of Scratch blocks. It holds procedures for the selected sprite. They are color-coded pink. Before any blocks are created, it is empty, except for a "Make a Block" button. Clicking this button brings up a dialogue asking for the block name. Then, enter the desired name as well as any inputs, and create the block.
define custom block
A define block from More Blocks in Scratch 2.0.
The past versions of the Define block

This category can technically have an unlimited amount of blocks, due to its blocks being user-created, but it has 1 type of stack block and 1 type of hat block (albeit modified).

Blocks

Note Note: Click on a block to learn more about it.

Scratch 3.0 has the following 1 hat block in More Blocks:

Scratch 3.0 has the following 1 Stack block in More Blocks:

Uses of Custom Blocks

Procedures are (apart from variables) the main kind of abstraction used in procedural programming; they let Scratchers write scripts without knowing or thinking about the exact details of what each script must do. This is also true of Scratch's primitive blocks, like move () steps. For example, suppose a Scratcher wants a sprite to vanish and reappear. To vanish, the sprite must play a sound effect and repeatedly increase the ghost effect; to reappear, it must repeatedly decrease the ghost effect. This must happen at several points in the project. Without procedures, the same sequence of blocks must be duplicated at each point. By making "vanish" and "appear" blocks, the user can now write scripts exactly as they think of them:

. . .
think [Hmm...] for (2) secs
vanish
. . .
appear
play sound [Whinny v] until done
. . .

define vanish
start sound [Ripples v]
repeat (10)
    change [ghost v] effect by (10)
end

define appear
repeat (10)
    change [ghost v] effect by (-10)
end
The Make a Block dialog

(They also have secondary benefits like reducing project file size, and disabling screen refresh.) Number, string, and Boolean inputs can be added to custom blocks. This allows procedures to be general; for example, rather than make several blocks each of which jumps a different distance, a Scratcher could add a "height" input to make a jump () :: custom block. (height :: custom-arg) will then appear in the Define block, and can be dragged out and used in the definition just as a variable would be.

Run without screen refresh

Using custom blocks is the only way to run scripts without screen refresh. Screen refresh is the very miniscule wait between each block in a script. When creating the title of a custom block, there are buttons to add inputs and a checkbox that allows you to disable screen refresh (by default it is enabled.) When the box is checked and the custom block runs, it will perform in an instant, which can be beneficial for setting up a particular scene in a project or performing large mathematical calculations, possibly in a game with artificial intelligence.

Workaround

Main article: List of Block Workarounds

In most simple cases, custom blocks can be worked around by using broadcasts and variables. However, this does not allow recursion, disabling screen refresh, or for multiple scripts to use the same procedure at the same time.

when gf clicked
broadcast [jump v] and wait

when I receive [jump v]
repeat (5)
    change y by (6)
end
repeat (5)
    change y by (-6)
end

Procedures in Snap!

Snap!, previously called BYOB, is a graphical programming language based on Scratch. Among other things (the most important of which are first class procedures and first class lists) Snap! allows making reporters and predicates as well as stack blocks.

Common Suggestions

Document.png Please expand this article or section. You can help by adding more information if you are an editor. More information might be found in a section of the talk page. (April 2019)

Many Scratchers would like the ability to make custom reporter and boolean blocks.[1] Additionally, dropdown inputs as arguments have also been requested, to the extent that some people used JSON hacking to insert them into custom blocks (though this does not work in Scratch 3.0.)

References

  1. AonymousGuy. (10/11/2013). "CUSTOM REPORTER BLOCKS[suggestion]" topic:20661