I’m trying to colour new variables differently by their names in order to make it easier for a user to identify where each of their variables are being used in their program. I am currently calling my recolour function in the createVariableButtonHandler. This works if the variables are instantiated in the workspace but when a new variable is created the colour of all of the variables in the toolbox are overwritten. Is there a way in which I can separately colour for example the variable getter block based on the user inputted name of that block?
Thank you Rachel, I have the colours being updated in the change and create block event listeners. This works perfectly in the workspace but not in the toolbox.
In the toolbox I am colouring the blocks by type using a function I found in a previous thread (shown below). This is ok for the math change and variables set blocks as I can colour them based on the colour of firstVariable (I have a dictionary matching variable Ids to hue values) in Blockly.Variables.flyoutCategoryBlocks. This wont work for the getter block as there is more than one in the toolbox.
Is there a way of colouring getter blocks in the toolbox separately?
recolor(Blockly.Blocks['variables_get'], myhue);
function recolor(block, hue) {
var oldInit = block.init;
block.init = function() {
oldInit.call(this);
this.setColour(hue);
}
}