(Redirected from Modding Tutorial)
|This article or section documents a feature 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
|Note:||This is a tutorial on modding Scratch 1.4. If you want to mod Scratch 2.0, use this tutorial on the forums.|
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.
|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.|
|Note:||You will probably want to rename cat2 to cat1, cat3 to cat2 etc...|
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.
move (10) stepsis:
('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.|
move (10) stepsblock, the string is this:
'move %n steps'That makes
move (10) stepshave 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) stepsblock 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.