(a little rephrasing)
Line 1: Line 1:
 
{{unreleased}}
 
{{unreleased}}
'''Procedures''', also called ''functions'' or ''methods'', are a tool in many programming languages, which allow common blocks of code to be grouped and called by a single name. [[Blocks]] in Scratch are procedures themselves, as they are blocks of compiled code executed all at once. Procedures have inputs or [[argument]]s, which are used to edit the procedure's effect slightly. For example, the "move (10) steps" block has the numerical argument (the bracketed bit) which specifies the distance to be moved: 10 pixels in this case.
+
'''Procedures''' allow you to make your own programming blocks. They allow a sequence of blocks to be grouped together and called by a single name.
 +
 
 +
Procedures can be found in many programming languages, and may also be called ''functions'' or ''methods''.
 +
 
 +
You can think of the [[blocks]] in Scratch 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==
 
==Procedures in Scratch==
 
[[File:Jump Block.png|thumb|A "jump" procedure {{-}} Scratch pre-alpha at Scratch Day 2011.]][[File:Jump block with insert.png|thumb|A "jump" procedure with an argument {{-}} Scratch pre-alpha at Scratch Day 2011.]]
 
[[File:Jump Block.png|thumb|A "jump" procedure {{-}} Scratch pre-alpha at Scratch Day 2011.]][[File:Jump block with insert.png|thumb|A "jump" procedure with an argument {{-}} Scratch pre-alpha at Scratch Day 2011.]]
 
[[File:Scratch-2.0-factorial-script.png|thumb|Recursive factorial procedure {{-}} Scratch 2.0 alpha.]]
 
[[File:Scratch-2.0-factorial-script.png|thumb|Recursive factorial procedure {{-}} Scratch 2.0 alpha.]]
Procedures have been added in [[Scratch 2.0]].<ref>http://blog.scratch.mit.edu/2011/03/scratch-20-progress-report-create-your.html</ref> There is a "[[More Blocks]]" palette, where procedures in the project are stored.<ref>http://blog.scratch.mit.edu/2012/02/scratch-20-project-page-and-project.html</ref> This palette also houses a "make a block" button, similar to the "make a variable/list" buttons in [[Data Blocks]]. 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)|() block]] is created in the palette. The procedures are available to the sprite with the Define block.<ref>http://scratch.mit.edu/forums/viewtopic.php?pid=719181#p719181</ref> Procedures in Scratch 2.0 are only [[Stack Blocks]], not Reporter or Boolean block styles, and support [[Recursion|recursion]]. Procedures take [[arguments]] of [[strings]], numbers, and [[Boolean]]s. Reporter or boolean procedures will not be available in Scratch 2.0, but may be in future versions.<ref>http://scratched.media.mit.edu/discussions/scratch-20/custom-block-types</ref> Procedures will run [[atomicity|atomically]].
+
 
 +
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>
 +
 
 +
<scratchblocks>
 +
custom block [hi] (42) <touching color [#0bb]?>
 +
 
 +
define custom block (string) (number) <boolean>
 +
</scratchblocks>
 +
 
 +
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|recursion]], so blocks can call themselves. (This doesn't stop the current block executing, unlike [[broadcasts]]). They can be set to run [[atomicity|atomically]] or "all at once".
  
 
==Procedures in [[BYOB]]/Snap!==
 
==Procedures in [[BYOB]]/Snap!==

Revision as of 16:41, 27 April 2013

Clock.png This article or section contains information about a feature from a future version of Scratch that is unreleased and is subject to change. Please cite any additional info in order to prevent speculation.

Procedures allow you to make your own programming blocks. They allow a sequence of blocks to be grouped together and called by a single name.

Procedures can be found in many programming languages, and may also be called functions or methods.

You can think of the blocks in Scratch as being procedures themselves, but made out of compiled code and not other blocks. Procedures can have inputs, or 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

A "jump" procedure — Scratch pre-alpha at Scratch Day 2011.
A "jump" procedure with an argument — Scratch pre-alpha at Scratch Day 2011.
Recursive factorial procedure — Scratch 2.0 alpha.

Procedures, or custom blocks, are one of the new features added in Scratch 2.0.[1]

Custom blocks are found in the "More Blocks" palette.[2] 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).

Custom blocks can have arguments of strings, numbers, and booleans. After naming and adding arguments, a 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 is created in the palette. The custom block is only available to the sprite that has the Define block.[3]

custom block [hi] (42) <touching color [#0bb]?>

define custom block (string) (number) <boolean>

Custom blocks can only be stack blocks, not reporters or booleans (though they may be added in the future).[4]. They support recursion, so blocks can call themselves. (This doesn't stop the current block executing, unlike broadcasts). They can be set to run atomically or "all at once".

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

References

  1. http://blog.scratch.mit.edu/2011/03/scratch-20-progress-report-create-your.html
  2. http://blog.scratch.mit.edu/2012/02/scratch-20-project-page-and-project.html
  3. http://scratch.mit.edu/forums/viewtopic.php?pid=719181#p719181
  4. http://scratched.media.mit.edu/discussions/scratch-20/custom-block-types