Определите пользовательские блоки
Оптимизируйте свои подборки
Сохраняйте и классифицируйте контент в соответствии со своими настройками.
Блоки — это то, что вы используете для программирования. Они представляют собой выражения и операторы в текстовых языках программирования.
Более подробную информацию о блоках и их частях можно найти в визуальном глоссарии .
Определение блока
Определение блока определяет соединения частей пазла и поля в вашем блоке. Большая часть внешнего вида и стиля ваших блоков определяется другими способами. Строка (обычно код), в которую преобразуется ваш блок, определяется как генератор кода блока .
Самый простой способ определения простых блоков — использование 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);

Дополнительную информацию о том, как определять блоки и добавлять их в набор инструментов, см. в разделе Обзор пользовательских блоков .
Если не указано иное, контент на этой странице предоставляется по лицензии Creative Commons "С указанием авторства 4.0", а примеры кода – по лицензии Apache 2.0. Подробнее об этом написано в правилах сайта. Java – это зарегистрированный товарный знак корпорации Oracle и ее аффилированных лиц.
Последнее обновление: 2025-07-24 UTC.
[[["Прост для понимания","easyToUnderstand","thumb-up"],["Помог мне решить мою проблему","solvedMyProblem","thumb-up"],["Другое","otherUp","thumb-up"]],[["Отсутствует нужная мне информация","missingTheInformationINeed","thumb-down"],["Слишком сложен/слишком много шагов","tooComplicatedTooManySteps","thumb-down"],["Устарел","outOfDate","thumb-down"],["Проблема с переводом текста","translationIssue","thumb-down"],["Проблемы образцов/кода","samplesCodeIssue","thumb-down"],["Другое","otherDown","thumb-down"]],["Последнее обновление: 2025-07-24 UTC."],[[["Blocks are the fundamental units used for programming in Blockly, representing expressions and statements like in text-based languages."],["A block definition determines its connections and fields, essentially shaping the block's structure and interactivity."],["Blockly utilizes JSON to simplify the process of defining blocks, allowing customization of text, inputs, and connections."],["Users can define their own custom blocks by specifying parameters such as type, message, arguments, and connections using JSON."],["Defined blocks need to be registered and then included in the toolbox for users to access and utilize them within Blockly's workspace."]]],["Blocks represent code expressions and statements. Block definitions specify connections and fields, while code generation defines the resulting code. The simplest method for defining blocks is JSON. A \"move forward\" block example shows the use of `type`, `message0`, `args0`, `previousStatement`, and `nextStatement` to define its structure. The block is registered using `Blockly.defineBlocks()`. Additional information is available on defining blocks and using the toolbox.\n"]]