It looks like it is not that simple to getFieldValue() when a shadow block is involved.
<category name="Sound" colour="20">
<block type="sound_play" id="sound_play">
<value name="SOUND_MENU">
<shadow type="sound_sounds_menu"></shadow>
</value>
</block>
</category>
These two extensions for reusability.
Blockly.Extensions.register('shape_statement', function() {
this.setInputsInline(true);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
});
Blockly.Extensions.register('output_string', function() {
this.setInputsInline(true);
this.setOutputShape(Blockly.OUTPUT_SHAPE_ROUND);
this.setOutput(true, 'String');
});
and these two blocks.
Blockly.Blocks['sound_sounds_menu'] = {
init: function() {
this.jsonInit({
"message0": "%1",
"args0": [
{
"type": "field_dropdown",
"name": "SOUND_MENU",
"options": [
['1', '0'],
['2', '1']
]
}
],
"extensions": ["output_string"]
});
}
};
Blockly.Blocks['sound_play'] = {
init: function() {
this.jsonInit({
"message0": Blockly.Msg.SOUND_PLAY,
"args0": [
{
"type": "input_value",
"name": "SOUND_MENU"
}
],
"extensions": ["shape_statement"]
});
}
};
Blockly.JavaScript['sound_play'] = function(block) {
block.getFieldValue('SOUND_MENU');
return null;
};
block.getFieldValue('SOUND_MENU') returned null all the time.
It worked on other blocks without shadow block.
Do I have to treat shadow block with special care?
To be honest, I don't really get the whole idea of shadow block. the
doc is not explaining it well. In the example I provided(copied from Scratch-Blocks), I guess I can just replace the shadow block with a drop down list and the result is the same?