|This article or section documents a feature not included in the current version of Scratch (2.0). It is only useful from a historical perspective.|
How difficult is it?
The difficulty depends on what you are trying to do. You have blockspecs and methods. The blockspecs are what define the block itself. The methods tell the block what to do.
Do I need any other programs?
All you need is Scratch or the Source Code. However, if you are having trouble, Scramble is a good way of getting started. You need to program in Squeak. A good way to start with Squeak is with Squeak Tutorial on this Wiki.
Making a block
Squeak is sometimes hard to get the hang of, so you can get the code for some custom blocks at the Block Library. You will soon get the hang of it.
Open the System Browser From the browser, go to:
- Click onto Class
- block specs
Adding the Block Spec
The block spec for each block is in brackets and uses the following structure:
('block text' #identifier #selector 'default' 'values')
Inputs are put the block text where desired. Each input has a
% followed by a letter representing the input type.
List of inputs:
— Attribute of another sprite, such as X position or size
— A boolean insert
— Color picker that shows the menu
— Color picker that does not
— The sprite direction menu/numerical insert
— The menu for MIDI drums
— The broadcast message menu
— Math function menu (with sin, abs, etc.)
— Menu for the different graphic effects
— Numerical sensor board selector menu
— Boolean sensor board selector menu
— MIDI instrument menu/numerical insert
— Menu for the names of the different keys
— Menu with the costume names of the current sprite
— List name menu
— Sprite list
— Numerical insert
— Note name menu/insert
— String insert
— Sound selector menu
— Variable menu
— Menu in Delete () of ()
List of identifiers:
— C Block
— Time block (such as Wait () Secs)
— 'When' Hat Block (obsolete)
— When Green Flag Clicked block
— When () Key Pressed block
— When I Receive () block
— Special form (hard to code)
For example, the blockspec for the repeat block is:
('repeat %n' #c #doRepeat 10)
When you are done, right-click in the System Browser and click accept.
Adding the code
Click 'instance' (next to class). Then click the appropriate 'op'. Add the code and command for the block. Right click and click accept.
Saving the image
|Warning:||Saving your Scratch image can only be undone by re-installing Scratch.|
Close the system browser. You may now test your new block. When you are done Shift-Click-R and click 'Save image for end user'. This will save your changes to Scratch.
- When modifying Scratch like this, It is a good idea to install two versions of Scratch, each in a different directory, in case something goes wrong. If something does go wrong and you do not have two versions, you can always reinstall Scratch.
- Better yet, you should download the source-code version of Scratch which you can edit separately. You can even distribute your changes as a Scratch Modification.