let block = {}; block['colour'] = colour; block['message0'] = `${rule['value']}`; block['args0'] = []; block['tooltip'] = template['uuid']; block['type'] = template['uuid']; block['enableContextMenu'] = true;
if (!template['rootRule']) block['previousStatement'] = true;
if (rule['value'].includes('When')) { // I only want this type of rule to have the extra context menu option
block['customContextMenu'] = function(options) { var option = { enabled: true, text: 'Custom option', callback: function(e) { console.log('custom context menu called\n', e); }, }; options.push(option); };
}
Blockly.Blocks[template['uuid']] = { init: function() { this.jsonInit(block); }, };
Enter code here...Enter code here...
All I need is one example of this working. I can't find any online.
Thanks in advance for anything you can do for me
Blockly.Blocks['test_block'] = {
init: function() {
this.appendDummyInput()
.appendField("testBlock");
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
},
customContextMenu: function(options) {
var option = {
enabled: true,
text: 'Custom option',
callback: function(e) {
console.log('custom context menu called\n', e);
},
};
options.push(option);
}
};