I’ve switched over to using NPM PXT-Blockly.
I’ve got some custom variable blocks for blockly of which are working fine with the create variable button apart from one feature.
For some reason the shadow block of which I am trying to place within the input of the “variables_set” block doesn’t show. I think this is because I’m declaring it within a toolbox file. Is there something else I need to do for that shadow block to appear?
Code:
Definition -
Blockly.Blocks['variables_set'] = {
init: function() {
this.appendDummyInput()
.appendField(new Blockly.FieldVariable(""), "VAR")
.appendField(new Blockly.FieldDropdown([['=', '='], ['+=', '+='], ["-=", "-="]]), 'NAME')
this.appendValueInput("varset")
.setCheck(null);
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour("#0000CD");
this.setTooltip("assign a value, increment, or decrement a variable");
this.setHelpUrl("");
}
};
Generator -
Blockly.Python['variables_set'] = function(block) {
var variable_name = Blockly.Python.variableDB_.getName(block.getFieldValue('VAR'), Blockly.Variables.NAME_TYPE);
var text_text = block.getFieldValue('NAME');
var value_name = Blockly.Python.valueToCode(block, 'varset', Blockly.Python.ORDER_ATOMIC);
// TODO: Assemble Python into code variable.
var code = variable_name + ' ' +text_text+ ' ' +value_name+ '\n';
return code;
};
Toolbox -
<block type="variables_set">
<value name="varset">
<shadow type="textinline">
<field name="text">0</field>
</shadow>
</value>
</block>
Does anyone know what I need to do to fix it?