盖帽次数

块是您用于编程的。它们使用基于文本的编程语言来表示表达式和语句。

如需详细了解数据块及其组成部分,请参阅可视化术语表

屏蔽定义

方块定义用于指定方块上的拼图块连接和字段。块的大多数外观和样式都是通过其他方式指定的。将块转换为的字符串(通常是代码)被定义为块代码生成器。

定义简单块的最简单方法是使用 JSON。

此代码段定义了一个“向前”块,其中包含下一个和上一个连接,以及一个距离字段。

// Create the definition.
const definitions = Blockly.createBlockDefinitionsFromJsonArray([
  {
    // The type is like the "class name" for your block. It is used to construct
    // new instances. E.g. in the toolbox.
    type: 'my_custom_block',
    // The message defines the basic text of your block, and where inputs or
    // fields will be inserted.
    message0: 'move forward %1',
    args0: [
      // Each arg is associated with a %# in the message.
      // This one gets substituted for %1.
      {
        // The type specifies the kind of input or field to be inserted.
        type: 'field_number',
        // The name allows you to reference the field and get its value.
        name: 'FIELD_NAME',
      }
    ],
    // Adds an untyped previous connection to the top of the block.
    previousStatement: null,
    // Adds an untyped next connection to the bottom of the block.
    nextStatement: null,
  }
]);

// Register the definition.
Blockly.defineBlocks(definitions);

未来发展的障碍

如需详细了解如何定义块,请参阅定义块

如需了解如何将代码块加入工具箱,请参阅工具箱概览