imagine • program • share

Scratch Team Blog: Scratch 2.0: Create your own block

Scratch 2.0: Create your own block

Saturday, March 26, 2011

Flash Player improvements

Thanks to everyone who reported bugs in the new flash-based Scratch project player! We’re now up to version 23 (the third version since the original release), and so far we’ve fixed over 20 confirmed glitches. Lots of Scratchers have posted detailed bug reports on the forums, which is really helpful. The more glitches we can find and fix now, the better we can make the flash player (and the next version of Scratch).


Create your own block

One of the new features we’re excited to add to Scratch is the ability to create your own blocks -- called “procedures” in the language of computer science. Creating your own blocks can be really handy. For example, let’s say you want to create an animation with a sprite that jumps in the air. Each time the sprite jumps, you need to tell it to go up, wait a little while, and then come back down again. That takes at least 3 blocks for every jump.

A simple “jump” script.

If you want to make your sprite jump, move, and then jump again, you might make something like this.

A “jump, move, jump” script.

In Scratch 2.0, you can do the same thing by creating your own jump block. You tell Scratch what your jump block does by creating a special script that defines the new block:

Creating a jump block to make a “jump, move, jump” script.

In this example, the jump block makes the sprite jump up, wait a half second, and then come down again. Each time Scratch comes to a jump block in a script (like the script on the left), Scratch runs the commands in the jump definition script (on the right). Combining the commands for jumping into a single block makes scripts easier to read.

In the next version of your project, you might want to be able to control how high your sprite jumps. Without the ability to make your own jump block, that could be a real pain. You’d have to find each and every “change y by 50” block that was used for jumping in your project, and change the 50 to something else. But with the new create-your-own-block feature, you can just add an input that tells the jump block how high you want it to jump.

Creating a jump block with a “height” input.

Now each time the jump block is run, the value of the height variable will be set to whatever number is entered as an input on the jump block. In this example, the first jump block has an input of 25, so the height variable will be set to 25 and the sprite will jump 25 pixels high. The second jump block has an input of 50, so the sprite will jump 50 pixels high.

We’re still in the process of figuring out the best way for Scratchers to create their own blocks, and there are still many questions. For example, if you create a jump block in one sprite, would other sprites be able to use the jump block too? Should the definition script appear in only one sprite -- and, if so, how would people find it? Should you be able to define “jump” differently in different sprites? These are few of the questions we have to think through before we’re ready to put this cool feature in the next version of Scratch.

Have ideas or thoughts about this? Post them in this thread in the Scratch forums.

9 comments :

fg123 said...

Looks really cool! Can I post here? It seems more organized. xD I was thinking when you make a block, it will be for only that sprite, unless you put it on the stage...

Scratch username is fg123 btw.

Teh Little said...

Come on Scratch Team. We are waiting with baited breath for 2.0!

Why do you care? said...

BETA TESTER TIME!!! please?

Etki said...

Why flash?!!! If you use GWT only web browser will be needed.

Etki said...

Why flash?!!! If you use GWT only web browser will be needed.

tcb said...

Isn't it basically the same as broadcating? (except for the local variable and arguments)

Ani Vegesana said...

Here is something that no other Squeak-Based programer (except in Scratch 1.2 BETA): make a 'when %b' block. And another one no other Squeak-Based programer has is a "splash.bmp" startup image in the folder of the program. When you open the progam, the image will show in the center of the running proccessor's monitor. The size of "splash.bmp" must be at least 1 pixel.

Ani Vegesana said...

Add upvars to repeat blocks. In the right-click menu, add a check box called "show repeat count". Delete the "if %b else" block from the control pallete and in the "if %b" block add a check box called "show else statement".

Berto said...

I love the visual programming elements. It makes it much easier to visualize the algorithms and organize yourself while programming.

Post a Comment

Note: Only a member of this blog may post a comment.