Question

198 views
Skip to first unread message

Mother Earth

unread,
Aug 7, 2024, 9:50:50 AM8/7/24
to Blockly
I've been exploring Google's Blockly library for a new project, and I'm encountering some challenges with customization and integration that I hope someone can help with. In our team, we're trying to create a custom block that extends Blockly's core functionality, but we're running into issues with rendering and compatibility with existing blocks.  

While attempting to develop a new block with unique functionality, we face problems with the block's appearance not rendering correctly. Additionally, integrating our custom blocks with existing Blockly categories causes unexpected behavior and errors.

Here's a simplified version of the code we're working with:

Blockly.Blocks['custom_block'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("Custom Block");
    this.setColour(230);
    this.setTooltip("");
    this.setHelpUrl("");
  }
};


When trying to integrate the custom block with existing Blockly categories, we encounter errors like TypeError: Cannot read properties of undefined.  

Christopher Allen

unread,
Aug 7, 2024, 12:15:56 PM8/7/24
to blo...@googlegroups.com
Hello,

When trying to integrate the custom block with existing Blockly categories, we encounter errors like TypeError: Cannot read properties of undefined.  

A little more context for where that error is occurring would be helpful, but I nevertheless have a pretty good guess.  In your block definition, you try to add a field of type "Custom Block" to your block:

Blockly.Blocks['custom_block'] = {
  init: function() {
    this.appendDummyInput()
        .appendField("Custom Block");
    this.setColour(230);
    this.setTooltip("");
    this.setHelpUrl("");
  }
};


The first parameter to appendField should be either a Field instance (or Field subclass instance) or the registered name of a field type (e.g. 'field_input') to be instantiated, and while it's certainly possible that you've created a custom Field subclass and registered it using the name 'Custom Block' I suspect you instead meant to use one of the standard built-in field types and give it the name Custom Block.  To do that the line should instead read .appendField('field_input', 'Custom Block') or similar.
 

Best wishes,

Christopher
Reply all
Reply to author
Forward
0 new messages