Blöcke werden zum Programmieren verwendet. Sie stellen Ausdrücke und Aussagen in textbasierten Programmiersprachen.
Weitere Informationen zu Blöcken und ihrer Darstellung finden Sie in den visuellen Glossar.
Block definition
Eine Blockdefinition gibt die Verbindungen und Felder Ihres Puzzleteils an. blockieren. Der Großteil des Aussehens und der Stils Ihrer Blöcke wird auf andere Weise angegeben. Die Zeichenfolge (normalerweise Code), in die der Block umgewandelt wird, wird als Blockcode definiert. Generator.
Einfache Blöcke lassen sich am einfachsten mit JSON definieren.
Mit diesem Code-Snippet wird ein Fortschritt definiert, mit „Weiter“ und „Zurück“ Verbindungen und ein Feld für die Entfernung.
// 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);
Weitere Informationen zum Definieren von Blockierungen finden Sie unter Definieren Sie Blöcke.
Informationen zum Hinzufügen des Blocks zu Ihrer Toolbox finden Sie unter Toolbox Übersicht.