m (Procedures in BYOB/Snap!: Links to Redirect Removal SEMI_AUTOMATIC)
m (redirected instead of deleting)
(40 intermediate revisions by 22 users not shown)
Line 1: Line 1:
'''Procedures''' allow for one to make their own programming blocks. They allow a sequence of blocks to be grouped together and called by a single name.
#REDIRECT [[My Blocks]]
Procedures can be found in many programming languages, and may also be called ''functions'' or ''methods''.
The [[blocks]] in Scratch can be thought of as being procedures themselves, but made out of compiled code and not other blocks. Procedures can have inputs, or [[argument|parameters]], which can give the procedure more information. For example, the "move (10) steps" block has a single argument, the number 10, which tells the block how far to move.
==Procedures in Scratch==
[[File:Jump Block.png|thumb|A "jump" custom block.]][[File:Jump block with insert.png|thumb|A "jump" custom block with number input.]]
[[File:Scratch-2.0-factorial-script.png|thumb|Recursive factorial procedure {{-}} Scratch 2.0 alpha.]]
Procedures, or custom blocks, are one of the new features added in [[Scratch 2.0]].<ref>http://blog.scratch.mit.edu/2011/03/scratch-20-progress-report-create-your.html</ref>
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> The palette starts off empty, and just shows a "make a block" button (similar to the "make a [[variable]]/list" buttons in the [[Data Blocks|data]] palette).
Custom blocks can have [[arguments]] of [[strings]], numbers, and [[boolean]]s. After naming and adding arguments, a [[Define () (block)|Define]] block is created. 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 created in the palette. The custom block is only available to the sprite that has the Define block.<ref>http://scratch.mit.edu/forums/viewtopic.php?pid=719181#p719181</ref>
custom block [hi] (42) <touching color [#0bb]?>
define custom block (string) (number) <boolean>
Custom blocks can only be [[Stack Block|stack blocks]], not [[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 doesn't 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]].  They can be set to run [[atomicity|atomically]] or "all at once".
==Procedures in BYOB/Snap!==
[[Snap!]], previously called [[Build Your Own Blocks (Scratch Modification)|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==
*[[() (Custom block)]]
*[[Define () (block)|Define ()]]
*[[Squeak Tutorial#Methods|Procedures in Squeak]]
[[Category:Scratch Program]]
[[Category:Scratch 2.0]]
[[Category:More Blocks]]

Latest revision as of 17:25, 6 January 2019

Redirect to: