- "Custom Block" redirects here. For the block itself, see () (Custom block).
|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
|Note:||Click on a block to learn more about it.|
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
(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.
- 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.
|Please expand this article or section. You can help by talk page. (April 2019)if you are an editor. More information might be found in a section of the|
Many Scratchers would like the ability to make custom reporter and Boolean blocks. 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.)
- AonymousGuy. (10/11/2013). "CUSTOM REPORTER BLOCKS[suggestion]" topic:20661