This article has links to websites or programs outside of Scratch and Wikipedia. Remember to stay safe while using the internet, as we cannot guarantee the safety of other websites. |
This article or section documents something not included in the current version of Scratch (3.0). It is only useful from a historical perspective. |
This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (August 2018) Reason: Not really comprehensive, doesn't teach enough |
- This article or section documents an outdated version of Scratch (version 1.4). For this article in the current version (version 3.0), see How to Make a Scratch Modification (3.0). For this article in Scratch 2.0, see How to Make a Scratch Modification (2.0).
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 Scratch users do not need Squeak installed to make their mod. The Squeak website is here.
Before Beginning
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.
Note: | A class is not to be confused with the term CLASS. This will get into further detail later. |
Before one makes 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 their 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
Warning: | Modifying Scratch may result in loss of elements. When editing, be sure to use care; some classes/methods may not be possible to restore, so it is recommended that you back up your work every time you make any changes. If you make a big mistake in modding, it will "break" your mod and render it unusable. |
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.
Note: | You will probably want to rename cat2 to cat1, cat3 to cat2 etc... |
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:)
Note: | This is what the blockSpecs look like in the Scratch System Browser. In the Source Code, the "#" are replaced with spaces. |
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. The Squeak Tutorial provides more information about how to code. This FAQ topic also provides detailed information.