Discuss Scratch

djdolphin
Scratcher
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

  1. If you don't already have it, install git.
  2. Run the command
    git clone https://github.com/LLK/scratch-flash
Compiling Scratch

You'll need to compile Scratch every time you make changes.
  1. Open a terminal.
  2. 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>
  3. If you're using a Unix-like OS, run
    ./gradlew build
    If you're using Windows, run
    gradlew.bat build
  4. 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 saying
    Redirection detected from https to http. Protocol switch unsafe, not allowed.
    then manually download OSMF_1.0.zip and put it in <your home directory>/.gradle/gradleFx/sdks/<some number>/in. (Thanks Jonathan50)

Last edited by djdolphin (March 9, 2018 22:19:47)


djdolphin
Scratcher
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 of
["block name", "block type", block category, "block primitive name", default arguments...]
Block Name
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.

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.
Block Type
The block type defines what shape a block will be. Valid values are:
  • “ ” - 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
Block Category
This defines what category a block will appear in. Valid values are:
  • 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
For 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.
Block Primitive Name
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 Arguments
The default values for arguments are defined here. For example,
["say %s for %n secs", " ", 2, "say:duration:elapsed:from:", "Hello!", 2]
makes the "say [ ] for ( ) secs" block have the default arguments “Hello” and 2.
Adding Block Primitives
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 of
primTable['<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>
}
That's it!

An Example, “Hello, world!” Block
In the Looks specs in the Specs.as, add the line
		["Hello, world!",						" ", 2, "helloWorld"],
In the addPrimsTo function in LooksPrims.as, add the line
		primTable['helloWorld']						= helloWorld;
In the LooksPrims.as file, add the function
	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();
}
If all goes well, it should make a sprite say “Hello, world!”.

Last edited by djdolphin (Dec. 31, 2015 05:18:53)


djdolphin
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

Tutorials by Other People

Last edited by djdolphin (Sept. 6, 2014 11:27:55)


djdolphin
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

Reserved

Last edited by djdolphin (March 20, 2015 00:05:52)


djdolphin
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

Reserved

davidkt
Scratcher
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.

Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog
djdolphin
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

davidkt wrote:

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.
Edit Specs.as to add block specs, and the blocks' code goes into one of the .as files in the primitives folder.

Last edited by djdolphin (May 16, 2014 00:15:12)


Mrcomputer1
Scratcher
500+ posts

Scratch 2.0 Modding for Newbs

what are the Reserved posts for?

My Profile / OS Projects / My User Page / My Talk Page / My website /
——————–
Progress bar to 1000+ Posts - Image not updated lots (Progress last updated: I forget to update this :P)

——————–
My browser / operating system: Windows 10 (NT 10.0), Firefox 59.0b13, Flash 28.0 (release 0)
——————–
My Scratch Extensions——–If you like this post then give me an internet!——–Sharp Scratch Mod
williambl
Scratcher
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 Cfake/path/to/flex.
should be
If you're using Windows, make sure to use back slashes ('\') as the directory separator instead of the normal forward slashes ('/'). For example, Cfake/path/to/flex becomes C:\fake\path\to\flex.
Linux and OS/X use ‘/’, while windows uses ‘\’. You've stated the opposite.

Last edited by williambl (May 16, 2014 06:26:18)


Blaaah.
arungupta
New to Scratch
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 ?
Mrcomputer1
Scratcher
500+ posts

Scratch 2.0 Modding for Newbs

arungupta wrote:

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 think it is the same

i don't know of any tutorials for creating plugins

Last edited by Mrcomputer1 (May 16, 2014 08:08:04)


My Profile / OS Projects / My User Page / My Talk Page / My website /
——————–
Progress bar to 1000+ Posts - Image not updated lots (Progress last updated: I forget to update this :P)

——————–
My browser / operating system: Windows 10 (NT 10.0), Firefox 59.0b13, Flash 28.0 (release 0)
——————–
My Scratch Extensions——–If you like this post then give me an internet!——–Sharp Scratch Mod
DigiTechs
Scratcher
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.

I do, in fact, have my own site; it's here.
I'm also working on a thing called Fetch. Look at it here!
@thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain.
DigiTechs
Scratcher
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

I do, in fact, have my own site; it's here.
I'm also working on a thing called Fetch. Look at it here!
@thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain. @thisandagain pls explain.
djdolphin
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

Mrcomputer1 wrote:

what are the Reserved posts for?
They're for later tutorials.

williambl wrote:

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 Cfake/path/to/flex.
should be
If you're using Windows, make sure to use back slashes ('\') as the directory separator instead of the normal forward slashes ('/'). For example, Cfake/path/to/flex becomes C:\fake\path\to\flex.
Linux and OS/X use ‘/’, while windows uses ‘\’. You've stated the opposite.
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.

DigiTechs wrote:

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.
I can't call it “Scratch 2.0 Modding for Dummies” because “for dummies” is trademarked.

arungupta wrote:

Is modding the same as creating a new plugin for Scratch ?

Is there any tutorial that shows how to create a simple plugin ?
It isn't the same, and Idon't know if any simple tutorials.

DigiTechs wrote:

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
I'll try that in Ubuntu later.

Last edited by djdolphin (May 16, 2014 10:38:53)


davidkt
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

djdolphin wrote:

davidkt wrote:

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.
Edit Specs.as to add block specs, and the blocks' code goes into one of the .as files in the primitives folder.
Thanks!!!!!!!

Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog
davidkt
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

Glad this is stickied. Any idea how to compile?

Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog
djdolphin
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

davidkt wrote:

Glad this is stickied. Any idea how to compile?
Eh, no one seems to read stickies. As for how to compile, look in the first post. I added instructions yesterday.

Last edited by djdolphin (May 17, 2014 18:02:46)


GP1
Scratcher
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
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

GP1 wrote:

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).
Okay.

davidkt
Scratcher
1000+ posts

Scratch 2.0 Modding for Newbs

djdolphin wrote:

davidkt wrote:

Glad this is stickied. Any idea how to compile?
Eh, no one seems to read stickies. As for how to compile, look in the first post. I added instructions yesterday.

davidkt wrote:

Thanks!!!!!!!

Last edited by davidkt (May 17, 2014 19:46:35)


Remember when I looked like this? I still do.


Float, my Scratch 2.0 mod | My (somewhat under-construction) blog

Powered by DjangoBB

Standard | Mobile