Revision as of 20:08, 2 February 2013 by Monster1612 (talk | contribs) (Procedures in Scratch: Correcting verb tenses in page)

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, 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 arguments, 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 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 have been added in Scratch 2.0.[1] There is a "More Blocks" palette, where procedures in the project are stored.[2] 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 is created. For each Define block (whether from the make a block button, or by dragging in from the backpack or another sprite), a () block is created in the palette. The procedures are available to the sprite with the Define block.[3] Procedures in Scratch 2.0 are only Stack Blocks, not Reporter or Boolean block styles, and support recursion. Procedures take arguments of strings, numbers, and Booleans. Reporter or boolean procedures will not be available in Scratch 2.0, but may be in future versions.[4] Procedures will run atomically.

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.

Procedures in Squeak

Main article: Squeak Tutorial#Methods

Procedures in Squeak are called methods.