[Scratch 3] Block Types You Can Develop and Samples
Cheatsheet for developing original block on Scratch 3
You can develop your own blocks for Scratch 3.0. I mentioned the method previously. It is powerful. Many children can use your invent.
If you do that, please note that you can choose types for block suitable for your aim. It is very important because different block types have the very different block looks and feeling of touch. If you want to do just one script on Scratch 3.0, you can use COMMAND
type. Others help some other wants to be done.
Let’s take a look.
INDEX: All types
- COMMAND ★★★★ super basic
- REPORTER ★★★ basic
- BOOLEAN ★★ advanced
- HAT ★★ advanced
- EVENT ★ professional
- CONDITIONAL ★ professional
- LOOP ★professional
- BUTTON ★ professional
1) COMMAND type block
This is the easiest block type to understand. COMMAND
executes one function as a command.
ACOMMAND
block can connect another block on top of it or on bottom of it. Blocks are executed in the order from top to bottom. So this COMMAND
block will be executed after upper block execute.
Definition ofCOMMAND
type block is as follows. blockType
is BlockType.COMMAND
.text
is a string showed on the face of block. If text
has []
, this field will be treated as variable field, which is user editable value.opcode
is the name of the function which implements this block’s operation.
The implementation of function is like this. COMMAND
block needs no return value. This example script only does assigning a value to text
and logging this value.
2) REPORTER type block
REPORTER
is also a fundamental function. REPORTER
is to create some value like String
or Integer
.
REPORTER
‘s value can be inputed into any variable fields. REPORTER
can be an input to COMMAND
. And REPORTER
can be an input to another REPORTER
.
Definition of REPORTER
type block is as follows.blockType
is BlockType.REPORTER
. Others are the same as COMMAND
.
The implementation of function is like this. REPORTER
must return some value.
3) BOOLEAN type block
BOOLEAN
type is special type of REPORTER
.
A little bit tricky thing is connection.
If one command block accepts boolean, the block shows like <=>
input form. If you have COMMAND and BOOLEAN
, of course, you can connect these blocks. This is natural.
But there is one more option. You will see the block which accepts REPORTER
. The block shows like (=)
input form. You may think it is impossible to connect this kind of COMMAND block and boolean. But you can do it like this.
Definition of BOOLEAN
is like this. blockType
is BlockType.BOOLEAN
. Others are the same as COMMAND
.
Implementation must return boolean value.
4) HAT type block
This is fundamental block type because this handles events. But implementation is a little bit tricky.
Definition of HAT is very simple like that.
As for HAT, key point is implementation. The following sample is the simplest implementation. It looks like good! send1
changes a value changed
. hat1 detects this change and seems to do commands next to hat.
You might want this block to keep detecting events. And you would kick send1 continuously. But some times it fails. Tricky point is that HAT
only detects when hat1
returns true after returning false previously. The next picture shows when HAT detects events.
When hat1
returns true
continuously, HAT
only detects one event. So confusing. But it is true.
So this technique is useful for avoiding this unexpected thing.
The following implementation avoids with using lasthat
which is the previous value of return value. Any time the previous return value was true, this function returns false
once. So events will be captured by HAT
.
Conclusion
You can use four fundamental block types. COMMAND, REPORTER, BOOLEAN, HAT. These are useful and suitable for each proper purpose. You can choose features of types and build your own blocks for Scratch 3.0.
Good luck!
Reference
Official extension specifications:
https://github.com/LLK/scratch-vm/blob/develop/docs/extensions.md