Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Scratch 2.0 Modding for Newbs
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs

2.0 Modding for Newbs
Here's a tutorial for making Scratch 2.0 mods, as they are somewhat harder to make than Scratch 1.4 mods. The purpose of this topic is to prevent a wave of people asking how to do this in the future. Please correct me if any of this information is wrong.
First off, Scratch 2.0 is programmed in a language called ActionScript. You'll need basic knowledge of it (or some other ECMAScript dialect) in order to follow most of this tutorial.
The New Way
Getting the Source Code
- If you don't already have it, install git.
- Run the command
git clone https://github.com/LLK/scratch-flash
Compiling Scratch
You'll need to compile Scratch every time you make changes.
- Open a terminal.
- Change the directory to the one containing the Scratch source code (the one containing the src directory, not the src directory itself) by running
cd <path to source code>
- If you're using a Unix-like OS, runIf you're using Windows, run
./gradlew build
gradlew.bat build
- If all goes well, Scratch can be found at build/11.6/Scratch.swf. If you get an error, and you've made changes to the code, then it's likely a problem with your code.
If you get an error sayingthen manually download OSMF_1.0.zip and put it in <your home directory>/.gradle/gradleFx/sdks/<some number>/in. (Thanks Jonathan50)Redirection detected from https to http. Protocol switch unsafe, not allowed.
Last edited by djdolphin (March 9, 2018 22:19:47)
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs
Adding Blocks
Adding Block Specs
Blocks are defined in the Specs.as file in the “src” file, in an array called commands. Each block definition is also an array, in the format ofAdding Block PrimitivesBlock Name["block name", "block type", block category, "block primitive name", default arguments...]The block's name contains the text, inputs, and icons on the block. Inputs (called arguments) are defined in the format of %<letter>.<optional menu type>. For example, %n creates a number input, and %m.direction creates a direction menu.Block Type
Icons are defined in the format of @<icon name>. For example, @greenFlag will create a green flag icon, and @stop will create a stop sign icon. You can find a complete list of argument types, menus, and icons here.The block type defines what shape a block will be. Valid values are:Block Category
- “ ” - a stack block
- “w” - a wait block defined in extensions
- “b” - a boolean
- “r” - a reporter
- “R” - requester, a reporter that requests data and waits until it's been received
- “h” - a hat block
- “c” - a C block
- “cf” - a final C block, like “forever”
- “e” - an “if then, else” shaped block
- “f” - a cap block, like "stop [all v]"
- “o” - the stack block outline for “define” blocks
- “p” - the “define” block shape
This defines what category a block will appear in. Valid values are:Block Primitive NameFor categories with blocks specific to the sprite and stage (like Looks), the number above defines a block for sprites only, and the number+100 defines the block for the stage only.
- 0 - undefined
- 1 - Motion
- 2 - Looks
- 3 - Sound
- 4 - Pen
- 5 - Events
- 6 - Control
- 7 - Sensing
- 8 - Operators
- 9 - Data
- 10 - More Blocks
- 11 - Parameter (inside custom block definitions)
- 12 - List
- 20 - Extension
This is the name of the “primitive” that defines what a block does. I'll show you how to define this later. If the block's primitive isn't defined, then the block will appear gray and do nothing.Default ArgumentsThe default values for arguments are defined here. For example,makes the "say [ ] for ( ) secs" block have the default arguments “Hello” and 2.["say %s for %n secs", " ", 2, "say:duration:elapsed:from:", "Hello!", 2]
Block primitives are defined in one of the files in the “primitives” folder, depending on the block's category. List primitives go in ListPrims.as, Looks primitives go in LooksPrims.as, Motion and Pen primitives go in MotionAndPenPrims.as, Sensing primitives go in SensingPrims.as, Sound primitives go in SoundPrims.as, Video Motion Primitives go in VideoMotionPrims.as, and all other primitives go in Primitives.as.
To define primitives, you need to add a line to the addPrimsTo function in one of the Primitives classes, in the format ofprimTable['<primitive name>'] = <function name>;
Then, in the same file, add a function for the primitive, with the format
private function <function name>(b:Block):void {
<code for block>
}
An Example, “Hello, world!” Block
In the Looks specs in the Specs.as, add the lineIn the addPrimsTo function in LooksPrims.as, add the line["Hello, world!", " ", 2, "helloWorld"],In the LooksPrims.as file, add the functionprimTable['helloWorld'] = helloWorld;If all goes well, it should make a sprite say “Hello, world!”.private function helloWorld(b:Block):void {
var s:ScratchSprite = interp.targetSprite();
if (s == null) return;
s.showBubble("Hello, world!", "talk", b);
if (s.visible) interp.redraw();
}
Last edited by djdolphin (Dec. 31, 2015 05:18:53)
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs
Tutorials by Other People
Last edited by djdolphin (Sept. 6, 2014 11:27:55)
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs
Reserved
Last edited by djdolphin (March 20, 2015 00:05:52)
- davidkt
-
1000+ posts
Scratch 2.0 Modding for Newbs
Do you know how to add blocks? I'm sifting through the four files of block code, trying to figure out where to start. Scratch 1.4 modding was definitely easier.
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs
Edit Specs.as to add block specs, and the blocks' code goes into one of the .as files in the primitives folder. Do you know how to add blocks? I'm sifting through the four files of block code, trying to figure out where to start. Scratch 1.4 modding was definitely easier.
Last edited by djdolphin (May 16, 2014 00:15:12)
- williambl
-
17 posts
Scratch 2.0 Modding for Newbs
I think I saw a mistake:
If you're using Windows, make sure to use forward slashes ('/') as the directory separator instead of the normal backslashes ('\'). For example, C:\fake\path\to\flex becomes Cshould befake/path/to/flex.
If you're using Windows, make sure to use back slashes ('\') as the directory separator instead of the normal forward slashes ('/'). For example, CLinux and OS/X use ‘/’, while windows uses ‘\’. You've stated the opposite.fake/path/to/flex becomes C:\fake\path\to\flex.
Last edited by williambl (May 16, 2014 06:26:18)
- arungupta
-
2 posts
Scratch 2.0 Modding for Newbs
Is modding the same as creating a new plugin for Scratch ?
Is there any tutorial that shows how to create a simple plugin ?
Is there any tutorial that shows how to create a simple plugin ?
- Mrcomputer1
-
500+ posts
Scratch 2.0 Modding for Newbs
i don't think it is the same Is modding the same as creating a new plugin for Scratch ?
Is there any tutorial that shows how to create a simple plugin ?
i don't know of any tutorials for creating plugins
Last edited by Mrcomputer1 (May 16, 2014 08:08:04)
- DigiTechs
-
500+ posts
Scratch 2.0 Modding for Newbs
The title should totally be ‘Scratch 2.0 Modding for Dummies’ instead.
Because, you know. I'm a dummy when it comes to these things.
Because, you know. I'm a dummy when it comes to these things.
- DigiTechs
-
500+ posts
Scratch 2.0 Modding for Newbs
http://helpx.adobe.com/flash-builder/release-note/flex-4-6-sdk-release.html has some useful tips for installing on Linux, and to install ant it's more than likely:
sudo apt-get install ant
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs
They're for later tutorials. what are the Reserved posts for?
Hmm… I'm not trying to say that OS X and Linux use \ as the directory separator. I'm trying to say that the local.properties files only suppprts forward slahes, whiles Windows users usually use backslashes. I'll try to tweak the phrasing. I think I saw a mistake:If you're using Windows, make sure to use forward slashes ('/') as the directory separator instead of the normal backslashes ('\'). For example, C:\fake\path\to\flex becomes Cshould befake/path/to/flex.
If you're using Windows, make sure to use back slashes ('\') as the directory separator instead of the normal forward slashes ('/'). For example, CLinux and OS/X use ‘/’, while windows uses ‘\’. You've stated the opposite.fake/path/to/flex becomes C:\fake\path\to\flex.
I can't call it “Scratch 2.0 Modding for Dummies” because “for dummies” is trademarked. The title should totally be ‘Scratch 2.0 Modding for Dummies’ instead.
Because, you know. I'm a dummy when it comes to these things.
It isn't the same, and Idon't know if any simple tutorials. Is modding the same as creating a new plugin for Scratch ?
Is there any tutorial that shows how to create a simple plugin ?

http://helpx.adobe.com/flash-builder/release-note/flex-4-6-sdk-release.html has some useful tips for installing on Linux, and to install ant it's more than likely:I'll try that in Ubuntu later.sudo apt-get install ant

Last edited by djdolphin (May 16, 2014 10:38:53)
- davidkt
-
1000+ posts
Scratch 2.0 Modding for Newbs
Thanks!!!!!!!Edit Specs.as to add block specs, and the blocks' code goes into one of the .as files in the primitives folder. Do you know how to add blocks? I'm sifting through the four files of block code, trying to figure out where to start. Scratch 1.4 modding was definitely easier.
- davidkt
-
1000+ posts
Scratch 2.0 Modding for Newbs
Glad this is stickied. Any idea how to compile?
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs
Eh, no one seems to read stickies. As for how to compile, look in the first post. I added instructions yesterday. Glad this is stickied. Any idea how to compile?

Last edited by djdolphin (May 17, 2014 18:02:46)
- GP1
-
100+ posts
Scratch 2.0 Modding for Newbs
I suggest that in your adding blocks section you add that if a block doesn't have corresponding code, the block will appear “gray”. That confused me a bit, since in Scratch 1.X adding a blockspec will color the block as well. (As a comment, that is a kinda smart move on the Scratch team's part, since now we know which blocks have code if we forget to program them in).
- djdolphin
-
1000+ posts
Scratch 2.0 Modding for Newbs
Okay. I suggest that in your adding blocks section you add that if a block doesn't have corresponding code, the block will appear “gray”. That confused me a bit, since in Scratch 1.X adding a blockspec will color the block as well. (As a comment, that is a kinda smart move on the Scratch team's part, since now we know which blocks have code if we forget to program them in).
- davidkt
-
1000+ posts
Scratch 2.0 Modding for Newbs
Eh, no one seems to read stickies. As for how to compile, look in the first post. I added instructions yesterday. Glad this is stickied. Any idea how to compile?
Thanks!!!!!!!
Last edited by davidkt (May 17, 2014 19:46:35)
- Discussion Forums
- » Advanced Topics
-
» Scratch 2.0 Modding for Newbs