Error: JavaScript generator does not know how to generate code for block type

380 views
Skip to first unread message

Zayn Abbas

unread,
Aug 8, 2024, 4:24:05 AM8/8/24
to Blockly
Hi,

I am trying to create custom blocks for my workspace and integrate it with R shiny. This works well for non-custom blocks, however when I create a custom block and hit run I get this error:

Error: JavaScript generator does not know how to generate code for block type. 

Here is my block definition and the function where I run it:

Blockly.Blocks['previous_average_index'] = {
init: function() {
this.appendValueInput("VALUE")
.setCheck("Number")
.appendField("Previous Average Index:");
this.setOutput(true, "Number");
this.setColour(230);
this.setTooltip("Input the Previous Average Index");
this.setHelpUrl("");
}
};
// Define the JavaScript generator code for the custom block
Blockly.JavaScript['previous_average_index'] = function(block) {
console.log("Enter Generator");
// Get the value from the block's input
var value = Blockly.JavaScript.valueToCode(block, 'VALUE', Blockly.JavaScript.ORDER_ATOMIC);
// Output the value as-is, without any additional function
var code = value;
return [code, Blockly.JavaScript.ORDER_NONE];
};

function getWorkspaceCode(workspace) {
// Generate JavaScript code from the workspace
console.log("This is the workspace: " + workspace);
console.log(Blockly.JavaScript.workspaceToCode(workspace));
return Blockly.JavaScript.workspaceToCode(workspace);
}
Any help would be appreciated!

Christopher Allen

unread,
Aug 8, 2024, 5:43:14 AM8/8/24
to blo...@googlegroups.com
Hello Zayn,

I am trying to create custom blocks for my workspace and integrate it with R shiny. This works well for non-custom blocks, however when I create a custom block and hit run I get this error:

Error: JavaScript generator does not know how to generate code for block type. 

Reply all
Reply to author
Forward
0 new messages