Hi,
I have a small Blockly program which appears to work. Within the program
I make use of a colourPicker to choose one of eight colours and associated
python code generator and it all behaves as expected.
Stupidly I decide to document what I have done! I set up a VM (using
virtualBox) with the same OS (Windows 10 pro) and go through the
process of documenting each feature as I add it. All works fine until I
get to the colour picker, at which point I get the error:
Unable to find [field_colour][field] in the registry.
I have compared my source files and they appear identical, the only difference
I can find is the working Blockly version is 10.1.13 while my code is failing
on 11.1.1. I may have forgotten to instal something in the VM that I did
originally - at 70 my memory is not that good ;-)
Any help appreciated.
Cheers
Paul
If needed my block definition code and generator are as follows:
Blockly.Blocks['colourPicker'] =
{
init: function () {
this.jsonInit({
"message0" : "%1",
"args0": [
{
"type": "field_colour",
"name": "COLOUR",
"colour": "#FF0000"
}
],
"extensions": ["set_colour_extension"],
"output" : "Number",
"colour" : 60,
"tooltip" : "Chooses one of the eight possible colours",
"helpUrl" : "./help/colourPicker.html"
});
}
}
var colourValues = ['#000000', '#0000FF', '#00FF00', '#00FFFF', '#FF0000', '#FF00FF', '#FFFF00', '#FFFFFF'];
var colourNames = [ 'black', 'blue', 'green', 'cyan', 'red', 'magenta', 'yellow', 'white' ];
var colourColumns = 3;
Blockly.Extensions.register('set_colour_extension',
function() {
var field = this.getField("COLOUR");
field.setColours( colourValues, colourNames);
field.setColumns(colourColumns);
});
python.pythonGenerator.forBlock['colourPicker'] = function(block, generator) {
var colours = ['#000000', '#0000ff', '#00ff00', '#00ffff', '#ff0000', '#ff00ff', '#ffff00', '#ffffff']
var colour_name = block.getFieldValue('COLOUR');
var colour_index = colours.indexOf(colour_name);
return [colour_index, Blockly.Python.ORDER_ATOMIC];
};