let child = block.getChildren()[0]
Blockly.JavaScript[block.type].call(block, block)
This generates this - which works :)
quando.every(1, function() {
var a=[function(){
quando.image_update_video("/client/media/traffic lights/red_light.png");
quando.setDefaultStyle('#quando_image', 'background-image', 'url("/client/media/traffic lights/red_light.png")');
},
function(){
quando.image_update_video("/client/media/traffic lights/green_light.png");
quando.setDefaultStyle('#quando_image', 'background-image', 'url("/client/media/traffic lights/green_light.png")');
}]
var i = Math.floor(Math.random() * a.length)
if (i == a.length) { i-- }
a[i]()
}, false); let PICK_RANDOM_BLOCK = 'Pick one at Random'
self.defineAdvanced({
name: PICK_RANDOM_BLOCK,
interface: [
{ statement: STATEMENT }
],
javascript : (block) => {
let stateBlock = block.getInputTargetBlock(STATEMENT)
let arr = 'var a=[' + _getIndividualChildCode(stateBlock, 'function(){\n', '}', ',\n') + ']'
return `${arr}\nvar i = Math.floor(Math.random() * a.length)\nif (i == a.length) { i-- }\na[i]()\n`
}
}) function _getIndividualChildCode(start, prefix, postfix, separator) {
let result = ''
let child = start
while (child != null) {
let code = quando_editor.getIndividualBlockCode(child)
if (result != '') {
result += separator
}
result += prefix + code + postfix
child = child.getNextBlock()
}
return result
} self.getIndividualBlockCode = (block) => {
let result = ''
if (block && !block.disabled) {
let javascript = Blockly.JavaScript[block.type]
if (javascript) {
result = javascript.call(block, block)
} else {
result = `Javascript missing for ${block.type}`
}
}
return result
}Rachel:Would it be possible to get an updated version of this example that doesn't use goog?