(AUTOMATED PROCESS: Using Template:Forum Archive)
(Fixed it up to standards)
Line 1: Line 1:
{{Outdated|information from the current version of Scratch. It is also not very clear what how they fully function and is not aimed toward a "has-no-clue" audience}}
+
'''Custom blocks''' allow for one to make his or her own programming [[blocks]]. Using custom blocks, large, similar scripts can be combined into one reusable block. In some other [[Programming Language|programming languages]], custom blocks are called "procedures", "functions", or "methods".  
'''Custom blocks''', known as "procedures", "functions", or "methods" in some other [[Programming Language|languages]], allow for one to make his or her own programming [[blocks]]. They allow a sequence of blocks to be grouped together and called by a single name. By utilizing custom blocks, large similar scripts with only minor differences can be broken down into one custom block. They help people follow the DOY rule of "don't repeat yourself".
 
  
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.
+
[[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.]]
  
==Creating a Custom Block==
+
==Custom Blocks in Scratch==
To create a custom block, access the "More Blocks" [[Block Categories|category]] of the [[Block Palette|blocks palette]], and select "New custom block". From there a menu will be opened prompting for the specific details of the block. The name can be typed into the text insertion located where the cursor is. The purple block resembles what the custom block will look like after it is created. When finished naming the block and adding any settings in the menu's Edit options, click "Ok". The custom block will appear in the palette and a hat block defining the block's procedure will appear in the [[Scripts Area|scripts area]]. The block can later be modified by right-clicking on it in the blocks palette and selecting "Edit".
+
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). 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>{{Forum Archive|59483|page=4|p=719181}}</ref>
  
==Procedures in Scratch==
+
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]].
[[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.]]
 
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>{{Forum Archive|59483|page=4|p=719181}}</ref>
+
==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. By pressing "Options", you can add [[string]], number, and [[boolean]] [[inputs]]. You can also add more label text to the block, or make it [[Single Frame|run without screen refresh]]. After naming and adding arguments, a [[Define () (block)|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 to its Define block, as shown below.
  
 
<scratchblocks>
 
<scratchblocks>
custom block [hi] (42) <touching color [#0bb]?>
+
spin right (360) degrees
  
define custom block (string) (number) <boolean>
+
define spin right (amount) degrees
 +
repeat (amount)
 +
turn right (1) degrees
 +
end
 
</scratchblocks>
 
</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]], 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]].  Custom blocks can be set to "run without screen refresh", which makes them execute within one frame.
 
  
 
==Procedures in BYOB/Snap!==
 
==Procedures in BYOB/Snap!==

Revision as of 18:38, 15 July 2014

Custom blocks allow for one to make his or her own programming blocks. Using custom blocks, large, similar scripts can be combined into one reusable block. In some other programming languages, custom blocks are called "procedures", "functions", or "methods".

A "jump" custom block.
A "jump" custom block with number input.
Recursive factorial procedure — Scratch 2.0 alpha.

Custom Blocks in Scratch

Custom blocks are found in the "More Blocks" palette.[1] 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). 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 shown in the palette. The custom block is only available to the sprite that has the Define block.[2]

Custom blocks can only be stack blocks, not reporters or booleans (though they may be added in the future).[3] They support recursion, so blocks can call themselves (This doesn't stop the current block executing, unlike broadcasts). This allows for things like creating fractals and finding the factorial of a number.

Creating a Custom Block

To create a custom block, open the "More Blocks" category and press the "Make a Block" button. A new block menu will open, where you can name your custom block. By pressing "Options", you can add string, number, and boolean inputs. You can also add more label text to the block, or make it run without screen refresh. After naming and adding arguments, a 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 to its Define block, as shown below.

spin right (360) degrees

define spin right (amount) degrees
repeat (amount)
turn right (1) degrees
end

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/2012/02/scratch-20-project-page-and-project.html
  2. https://scratcharchive.asun.co/forums/viewtopic.php?pid=719181#p719181
  3. http://scratched.media.mit.edu/discussions/scratch-20/custom-block-types