בלוקים הם השיטה שבה משתמשים כדי לתכנת. הם מייצגים ביטויים והצהרות בשפות תכנות מבוססות-טקסט.
למידע נוסף על בלוקים ועל איך נראים החלקים שלהם, אפשר לעיין מילון מונחים חזותי.
הגדרת חסימה
הגדרת בלוק מציינת את החיבורים והשדות של חלקי הפאזל חסימה. רוב המראה והסגנון של הבלוקים מוגדרים בדרכים אחרות. מחרוזת (בדרך כלל קוד) שאליו הבלוק שלך מומר מוגדר כblock-code Generator.
הדרך הקלה ביותר להגדיר בלוקים פשוטים היא באמצעות 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);
למידע נוסף על אופן הגדרת בלוקים, ראו הגדרת בלוקים.
למידע נוסף על הדרך להכללת בלוק בארגז הכלים שלך, ראה ארגז כלים סקירה כללית.