阻攻次數

區塊可用來編寫程式。代表 文字式程式設計語言

如要進一步瞭解區塊和 `其中各個部分的外觀,請參閱 視覺化詞彙表

封鎖定義

方塊定義則用來指定地球物體的連接和領域 封鎖。您可使用其他方式指定區塊的大部分外觀和樣式。 系統轉換為區塊的字串 (通常是程式碼) 將由系統定義為區塊程式碼 產生器

定義簡易區塊最簡單的方法是使用 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);

推動未來創作的方塊

如要進一步瞭解如何定義區塊,請參閱 定義區塊

若要瞭解如何在工具箱中加入封鎖條件,請參閱工具箱 總覽頁面