The generators link that you sent to me helped. I was looking for it.
I used that in the generator of my block, but it is still not working. I would like to be able to see the result printed on the screen.
//Block definition
Blockly.Blocks['oldrule'] = {
init: function() {
this.appendDummyInput()
.appendField("Rule")
.appendField(new Blockly.FieldTextInput("default"), "number_rule");
this.appendValueInput("anteced")
.setCheck(null)
.setAlign(Blockly.ALIGN_RIGHT)
.appendField("if");
this.appendStatementInput("conseq")
.setCheck(null)
.appendField("then");
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(210);
this.setTooltip("");
this.setHelpUrl("");
}
};
//Generator stub
Blockly.JavaScript['oldrule'] = function(block) {
var n = 0;
var code = '', statements_conseq, value_anteced;
do {
var text_number_rule = block.getFieldValue('number_rule');
value_anteced = Blockly.JavaScript.valueToCode(block, 'anteced' + n, Blockly.JavaScript.ORDER_NONE) || 'false';
statements_conseq = Blockly.JavaScript.statementToCode(block, 'conseq' + n);
// TODO: Assemble JavaScript into code variable.
code += 'if (' + value_anteced + ') {\n' + statements_conseq + '}'; //code += (n > 0 ? ' else ' : '') +
++n;
} while (block.getInput('anteced' + n));
/*if (block.getInput('ELSE')) {
statements_conseq = Blockly.JavaScript.statementToCode(block, 'ELSE');
code += ' else {\n' + statements_conseq + '}';
}*/
return code + '\n';
};