تحديد الوحدات الأساسية المخصّصة

الكتل هي ما تستخدمه للبرمجة. وهي تمثّل التعبيرات والبيانات في لغات البرمجة المستندة إلى النصوص.

لمزيد من المعلومات عن الكتل وأجزائها، اطّلِع على مسرد المصطلحات المرئية.

تعريف الحظر

يحدِّد تعريف المربّع اتصالات قطع الأحجية والحقول في المربّع. يتم تحديد معظم مظهر الوحدات وأسلوبها بطرق أخرى. يتم تعريف السلسلة (التي تكون عادةً رمزًا) التي يتم تحويل العنصر إليها باسم أداة توليد رمز العنصر.

إنّ أسهل طريقة لتحديد الكتل البسيطة هي استخدام تنسيق JSON.

يحدِّد مقتطف الرمز هذا وحدة "الانتقال إلى الأمام" باستخدام ربطين "التالي" و"السابق"، وحقل واحد للمسافة.

// Create the definition.
const definitions = Blockly.common.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.common.defineBlocks(definitions);

خطوة للأمام

لمزيد من المعلومات عن كيفية تحديد الوحدات وإضافتها إلى صندوق الأدوات، اطّلِع على نظرة عامة على الوحدات المخصّصة.