My blocks
My blocks
allow you to create new blocks for a sprite. You give the block a name and then define
what the new block does using other Scratch blocks. You can use your new block in any script on the sprite that owns the block.
This example defines a talk
block that makes a sprite change costume:
Penguin chirps: See inside
You can use My blocks
to organise your code. It’s simpler to group together all the blocks that make a sprite talk and then just use one talk
block when you want your sprite to talk.
If you decide that you want to change the way your sprite talks then you only have to change the code in one place.
My blocks with inputs
You can also add inputs to My blocks
so that they use the values you provide when you use the block.
Penguin talks: See inside
Making a block
- Click on My Blocks, and then click Make a Block.
- Give your new block a name and then click OK.
- You will see a new
define
block. Attach code to this block.
- You can then use your new block just like any normal block.
- The code attached to your new
define
block is run whenever the block is used.
Making a block with parameters
- You can also create blocks that have ‘gaps’ for adding data. These ‘gaps’ are called ‘parameters’. To add parameters, first make a new block, and then click on the options below to choose the type of data you want to add. Then give your data a name, and click OK.
- You will see a new
define
block as usual, except that this one contains the data gap you added and which you gave a name.
- You can then use your new block, filling in data in the gap.
- As usual, the code attached to your new
define
block is run whenever the block is used.
Use My Blocks to organise code
My blocks
are similar to ‘procedures’, ‘functions’ or ‘methods’ in other programming languages.