Eng:How to Make a Scratch Modification

Although Scratch can seem complicated to some users, some Scratchers make Mods, or Modifications of the program to add more elements and blocks. Scratch was developed in Squeak, however one does not need Squeak installed to make your mod. The Squeak website is here.

Before you Begin
When creating a Scratch Modification, one would open the System Browser to edit and modify (often shortened to mod) the source code. The code is made up of classes and, within those, are methods.

Before you make a Scratch Modification, they must have the following:


 * Scratch installed on their system
 * The Scratch 1.4 Source Code downloaded
 * ScratchUISkin (optional)
 * Graphics editing program (i.e. paint, paintbrush, Scratch paint editor, etc...) (optional)
 * Some knowledge of Scratch and Squeak
 * Ideas for a Scratch Modification
 * A name for your mod

Setting up your Mod's folder
As previously mentioned, One would edit the coding in the System Browser, and modify the classes and methods to add or change features

The first step is to rename the Scratch Source Code folder, ScratchSkin folder (optional), and image file to your Mod's title. Make a new folder for your Mod, and put the Source Code folder and Scratch Skin folder in it (optional). Copy the "media" folder from the Scratch program folder to your mod's new folder and delete Gobo and the Scratch Cat. To edit the Source Code, simply open the file: "ScratchSourceCode [version] " with the Scratch application. Shift-click the File menu, choose "Exit user mode," click the white area that appears, choose "open...," and choose "browser." Select the box titled: "System Browser". This is basically the whole program in the Squeak language!

Editing the Source
There are 4 menus in the System Browser. Select "Scratch-Objects", then "ScratchSpriteMorph". Under that menu pane is 3 buttons: "instance", "?", and "class". Select "class". On the right is another menu. Select "block specs", then "blockSpecs". Now you're ready to start adding blockSpecs! "BlockSpecs" are Block Specifications. They tell Squeak what content should be on a specific block.

For example, the blockSpec for move (10) steps is:

('move %n steps' #- #forward:)

2 quotes () define a "string''". In between the quotes, goes the text. Any text is considered a "string". In the move (10) steps block, the string is this: 'move %n steps' That makes move (10) steps have the title that it has. You might be wondering, "What about the %n part?" %n is the number input. It allows users to type a number into a box. Let's look again at the #- part. That defines that it's a stack block. There are different Block Types, and in each blockSpec, that part is important. For a reporter block, r is used. For a boolean block, b is used. The forward: part calls the method, "forward:". The "method" is the actual code that the block uses to function. The move (10) steps block has a method titled "forward:", and is the following: 

forward: distance "Move the object forward (i.e., the direction of its heading) by the given distance.	Avoid infinite or NaN coordinates"

| radians deltaP newPos newX newY | radians _ rotationDegrees degreesToRadians. deltaP _ ((radians cos)@(radians sin)) * distance. newPos _ self position + deltaP. newX _ newPos x. newY _ newPos y. newX isNaN ifTrue: [newX _ 0]. newX isInf ifTrue: [newX _ newX sign * 10000]. newY isNaN ifTrue: [newY _ 0]. newY isInf ifTrue: [newY _ newY sign * 10000]. self position: newX @ newY. self keepOnScreen.

The first "distance" is a "variable". It is defined by the input. The rest of the method is more advanced, but that is only because the block is more advanced than some others. This block seems very simple, but when you know how Scratch does it, you'll see why! See the block workaround for it.

Conclusion
This so far has been just the basics of Squeak. You can learn more coding by reading the Squeak Tutorial. You may also find [ this] FAQ informative too.