Skip to content

How to add new blocks

Daniel Esteban edited this page Sep 28, 2020 · 2 revisions

Components are called "blocks" in blockly language. A component could be a function, a sensor or a device. To add a new block you need to:

Modify or add a new file in blocks folder. If it's your first time, you could copy one of the existing files and use it as a template. You could group several blocks in a single file. For example blocks/gopherbot.js contains all related Gopherbot's blocks.

Additionally, you need to add the newly created file to playground/playground.html , on top, see lines 19-29 as example

<script src="../blocks/my-custom-blocks.js"></script>

Finally, add the new blocks to the menu (see example lines 869-876):

    <category name="My Custom Blocks">
      <block type="my_custom_blocks_my_block_id" categorystyle="text_category"></block>
      <block type="my_custom_blocks_another_block_id" categorystyle="text_category"></block>
    </category>

Block Factory

You could use the Blockly Developer Tools to visually create new blocks' definition, and then manually add the code part.

Clone this wiki locally