블록

블록은 프로그래밍에 사용하는 것입니다. 텍스트 기반 프로그래밍 언어로 된 표현식과 문을 나타냅니다.

블록 및 블록의 각 부분에 관한 자세한 내용은 시각적 용어집을 참조하세요.

차단 정의

블록 정의는 블록의 퍼즐 조각 연결 및 필드를 지정합니다. 블록의 모양과 스타일 대부분은 다른 방식으로 지정됩니다. 블록이 변환되는 문자열 (일반적으로 코드)은 블록 코드 생성기로 정의됩니다.

단순한 블록을 정의하는 가장 쉬운 방법은 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);

앞으로 나아갈 수 있는 블록

블록을 정의하는 방법에 관한 자세한 내용은 블록 정의를 참고하세요.

도구 상자에 블록을 포함하는 방법에 관한 자세한 내용은 도구 상자 개요를 참고하세요.