Bloki

Do programowania wykorzystujesz bloki. Reprezentują wyrażenia i wyrażenia w języków programowania opartego na tekście.

Więcej informacji na temat bloków i ich wyglądu znajdziesz w glosariusz wizualny.

Definicja blokowania

Definicja bloku określa połączenia i pola elementów układanki na Twoim blokować. Większość wyglądu i stylu brył została określona na inne sposoby. Ciąg znaków (zwykle kod), do którego zostanie przekonwertowany blok, jest zdefiniowany jako kod blokowy .

Najłatwiejszym sposobem zdefiniowania prostych bloków jest użycie formatu JSON.

Ten fragment kodu definiuje „przesuwanie do przodu” blokuj za pomocą opcji następny i poprzedni połączenia i jedno pole na odległość.

// 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);

Blok na przyszłość

Więcej informacji na temat definiowania bloków znajdziesz w sekcji Zdefiniuj bloki.

Informacje na temat dodawania bloków do narzędzi znajdziesz w sekcji Zestaw narzędzi .