(←Replaced content with "{{delete|Merged to My Blocks; duplicate article}}")
Line 1: Line 1:
{{featured|July|2016}}{{redirect|Custom Block|the block itself|() (custom block)}}
{{delete|Merged to [[My Blocks]]; duplicate article}}
'''Custom blocks''' allow for one to make their own programming [[blocks]]. Using custom blocks, similar scripts can be compressed into one reusable block. In some other [[Programming Language|programming languages]], custom blocks are called "procedures," "functions," or "methods." This block is useful for reusing a sequence of blocks in different parts of code, without duplicating the blocks each usage.
[[File:Scratch-2.0-factorial-script.png|thumb|Recursive factorial procedure {{-}} Scratch 2.0 alpha.]]
==Custom Blocks in Scratch==
Custom blocks are found in the "[[More Blocks]]" palette.<ref>http://blog.scratch.mit.edu/2012/02/scratch-20-project-page-and-project.html</ref> This is an example of a "jump" block:
define jump (how far)
change y by (how far)
wait (0.5) secs
change y by ((0) - (how far))
when gf clicked
jump (10)
move (20) steps
jump (20)
The custom block palette starts off empty and only shows a "Make a Block" button (similar to the "Make a [[Variable]]/[[List]]" buttons in the [[Data Blocks|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)|custom block]] is shown in the palette. The custom block is only available to the sprite that has the Define block.<ref>[[ar-post:719181]]</ref>
Custom blocks can only be [[Stack Block|stack blocks]], and can not be [[Reporter Block|reporters]] or [[Boolean Block|booleans]] (though they may be added in the future).<ref>http://scratched.media.mit.edu/discussions/scratch-20/custom-block-types</ref> They support [[recursion]], so blocks can call themselves (This does not stop the current block executing, unlike [[broadcasts]]). This allows for things like [[Recursion and Fractals|creating fractals]] and [[Recursion#Recursion in Scratch 2.0|finding the factorial of a number]].
==Creating a Custom Block==
To create a custom block, open the "More Blocks" [[Block Categories|category]]  and press the "Make a Block" button. A new block menu will open, where you can name your custom block.
[[File:Custom Block Edit Menu.png|thumb|The edit menu for custom blocks]]
By pressing "Options", you can add [[string]], number, and [[boolean]] [[inputs]]. You can also add more label texts to the block, or make it [[Single Frame|run without screen refresh]].
After naming and adding arguments, a {{b|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 onto its Define block, as shown below.
spin right (360) degrees
define spin right (amount) degrees
repeat (amount)
turn right (1) degrees
{{note|When a custom block is created, it exists only for the [[sprite]] where it was created. To use a custom block in another sprite, you must create it again in that sprite.}}
==Scratch 1.x Workaround==
when gf clicked
set [how far v] to [50]
broadcast [jump v] and wait
when I receive [jump v]
change y by (how far)
wait (.5) secs
change y by ((0) - (how far))
==Procedures in BYOB/Snap!==
[[Snap!]], previously called BYOB (Build Your Own Blocks), is a [[Scratch Modification|Scratch modification]] that allows procedures. Snap!'s procedures allow all 3 types of blocks, with arguments, and also recursion.
==See Also==
* [[() (Custom block)]]
* [[Define () (block)|Define ()]]
* [[Squeak Tutorial#Methods|Procedures in Squeak]]
[[Category:Scratch Program]]
[[Category:Scratch 2.0]]
[[Category:More Blocks]]
[[nl:Meer Blokken]]

Revision as of 17:13, 6 January 2019

Document stub.png This page no longer has any use and needs to be deleted. The user who added this template does not have permission to delete the page. (Date?)
Reason for deletion: Merged to My Blocks; duplicate article
Admins and Experienced Wikians: remember to check the page history, what links here, patrol all unpatrolled edits, then delete this page.