Blok

Blok adalah apa yang Anda gunakan untuk memprogram. Mereka mewakili ekspresi dan pernyataan dalam bahasa pemrograman berbasis teks.

Untuk informasi selengkapnya tentang blok dan seperti apa `bagian-bagiannya, lihat glosarium visual.

Blokir definisi

Penentuan blok menentukan sambungan dan isian potongan {i>puzzle<i} pada diblokir. Sebagian besar tampilan dan gaya blok Anda ditentukan dengan cara lain. Tujuan {i>string<i} (biasanya kode) yang menjadi tujuan konversi blok Anda didefinisikan sebagai kode blok generator.

Cara termudah untuk menentukan blok sederhana adalah dengan menggunakan JSON.

Cuplikan kode ini mendefinisikan "maju" blokir dengan berikutnya dan sebelumnya koneksi, dan satu ruang isian untuk jarak.

// 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 untuk bergerak maju

Untuk informasi selengkapnya tentang cara menentukan pemblokiran, lihat Menentukan blok.

Untuk informasi tentang cara memasukkan blok Anda di kotak peralatan, lihat Toolbox ringkasan.