Hi everyone!
I am trying to create and customize a function block with a parameter (pElement). However, although in the block factory helped me defining the statement block, I don't find a way to call and use the parameter that I am requiring inside of it.
Here is the code that I have. Thank you for your collaboration!
Blockly.Blocks['insert_function'] = {
init: function() {
this.appendDummyInput()
.appendField("Define the Function: \"Insert an Element\"")
.appendField(new Blockly.FieldVariable("element"), "pElement");
this.appendStatementInput("INSERTED")
.setCheck("Number");
this.setColour(15);
this.setTooltip('');
}
};
Blockly.JavaScript[''insert_function'] = function(block) {
var pElement = Blockly.JavaScript.variableDB_.getName(block.getFieldValue('pElement'), Blockly.Variables.NAME_TYPE);
var statements = Blockly.JavaScript.statementToCode(block, 'INSERTED');
// TODO: Assemble JavaScript into code variable.
var code = statements+';\n';
return code;
};