Build Your Own Block
Update time：2018-04-13 Views：4166
FireBlock let you build your own block, by combing the basic blocks together into one advanced block, to archive complex and specific function.
There are three basic type of blocks: Command, Reporter and Predicate.
Command executes a series of actions, without any return to the caller.
Reporter also executes a seris of actions, but has something (numberic, text, boolean or other) to return to the caller.
Predicate is actually a special version of Reporter, which returns boolean value (true or false) only to the caller.
In this example, we will draw build a customized block to draw a hexagon, which is also named hexagon, and accepts edge length as the only parameter.
Make a Block
1. Select category. Here we select "Pen". The newly made block will be found there in later use.
2. Input name "hexagon", and select block type as Command.
3 This block is of global use. Keep "for all sprites" checked.
As shown below:
Press "OK" to enter block editor:
We need to specify the edge length of the hexagon, that is, add a parameter edge to the block.
Click the "+" icon at the right of "hexagon", and in the popup parameter dialog, input "edge" as the name:
Click "OK", and get:
Now is the time to build blocks to draw a hexagon.
The drawing of hexagon is simple. It has six edges with the same length. Each angle is 120 degree. Therefore, we just repeat 6 times, each time draw the edge, and turn a degree (180-120=60) to the right.
During the building process, please note that "edge" parameter is draggable. In fact, it is like a "script variable", which be invalid outside the block:
Please "OK" to close the dialog.
We have made our own block.
Use Customized Block
You can find the newly made "hexagon" block in the "Pen" category. If you need to edit it again, just right click the block, select "edit..." in the popup menu:
Now have a try:
Click the block group, and the hexagon is drawn on the stage:
This is an example of using recursion (a block which calls itself) to draw a beautiful hexagon flower:
Click the test blocks. Wait some time, and you will be presented with: