การบล็อกคือสิ่งที่คุณใช้ในการเขียนโปรแกรม โดยเป็นตัวแทนของนิพจน์และข้อความใน ภาษาโปรแกรมแบบข้อความ
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับบล็อกและลักษณะของบล็อก โปรดดูที่ อภิธานศัพท์ภาพ
คำจำกัดความแบบบล็อก
คำจำกัดความแบบบล็อกจะระบุการเชื่อมต่อชิ้นส่วนและฟิลด์ของจิ๊กซอว์บน บล็อก รูปลักษณ์และสไตล์ส่วนใหญ่ของบล็อกของคุณจะถูกระบุด้วยวิธีอื่น string (มักจะเป็นโค้ด) การบล็อกที่ถูกแปลงจะกลายเป็น block-code เท่านั้น
วิธีที่ง่ายที่สุดในการระบุการบล็อกแบบง่ายคือการใช้ 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);
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับวิธีกำหนดบล็อกของคุณ โปรดดู กำหนดบล็อก
สำหรับข้อมูลเกี่ยวกับวิธีรวมบล็อกในกล่องเครื่องมือ โปรดดูที่กล่องเครื่องมือ ภาพรวม