I basically have two types of blocks: a rule block and a fact block (just like in Prolog). They can both be attached to each other. The rule block expects two inputs of the type 'fact'. However, it should not be possible to have multiple attached fact blocks as a single input. Therefore I had to set 'setNextStatement' to false whenever a fact block is attached as input of a rule block.
This is what I tried to do in the fact block:
this.setOnChange(function(changeEvent) {
if(changeEvent.type == Blockly.Events.MOVE) {
let prevBlock = this.getPreviousBlock();
if(prevBlock != null && prevBlock.type == "rule") {
let nextBlock = prevBlock.getNextBlock();
if((nextBlock != null && nextBlock != this) || (nextBlock == null)) {
this.setNextStatement(false);
}
} else {
this.setNextStatement(true);
}
}
});
And of course the rule block:
Blockly.Blocks['rule'] = {
init: function() {
this.appendDummyInput("RULE_DATA")
.appendField('Rule: ');
this.appendStatementInput('INPUT_HEAD')
.setCheck("fact")
.appendField("Head");
this.appendStatementInput('INPUT_BODY')
.setCheck("fact")
.appendField("Body");
...
This actually works, but when I separate a fact from the input part of a rule, I always get the following error:
Uncaught Error: Connection lists did not match in length.
at Blockly.BlockSvg.Blockly.Block.getMatchingConnection (blockly_compressed.js:1447)
at Blockly.InsertionMarkerManager.connectMarker_ (blockly_compressed.js:1125)
at Blockly.InsertionMarkerManager.showPreview_ (blockly_compressed.js:1118)
at Blockly.InsertionMarkerManager.maybeShowPreview_ (blockly_compressed.js:1117)
at Blockly.InsertionMarkerManager.update (blockly_compressed.js:1110)
at Blockly.BlockDragger.dragBlock (blockly_compressed.js:1130)
at Blockly.TouchGesture.Blockly.Gesture.startDraggingBlock_ (blockly_compressed.js:1177)
at Blockly.TouchGesture.Blockly.Gesture.updateIsDraggingBlock_ (blockly_compressed.js:1174)
at Blockly.TouchGesture.Blockly.Gesture.updateIsDragging_ (blockly_compressed.js:1176)
at Blockly.TouchGesture.Blockly.Gesture.updateFromEvent_ (blockly_compressed.js:1171)
Does somebody has any idea?