所以这是有问题的块
{
"type": "local",
"message0": "%{BKY_LOCAL_TITLE}",
"args0": [
{
"type": "input_dummy"
},
{
"type": "input_statement",
"name": "DEFINE",
"check": "Local"
},
{
"type": "input_value",
"name": "EXPRESSION"
}
],
"inputsInline": true,
"output": null,
"style":"local_blocks"
}
它用于函数的局部定义。
'Define' arg 包含许多函数和变量定义块。问题是如果我尝试访问定义,无论我做什么,我都只能得到堆栈中的第一个块。
我尝试使用 statementToCode 和 BlockToCode 直接调用它
Blockly.JavaScript.valueToCode(block, 'DEFINE', Blockly.JavaScript.ORDER_FUNCTION_CALL) ;
Blockly.JavaScript.statementToCode(block, 'DEFINE', Blockly.JavaScript.ORDER_FUNCTION_CALL);
Blockly.JavaScript.blockToCode(block.getInputTargetBlock('DEFINE')); //neither works
我试图做一个 for 循环,但 DEFINE0、DEFINE1 等不存在。
那么,您如何真正获得在 DEFINE 字段中堆叠的块?
编辑:我检查了 block.getChildren().length 并且它总是 2(所以表达式 + 定义)这意味着,正如预期的那样,定义列表嵌套在第一个孩子中。
另一个问题可能是定义列表是函数定义,即它们产生如下代码:
Blockly.JavaScript['define_name'] = function(block) {
[...]
Blockly.JavaScript.definitions_['%' + name] = code;
return null;
};
Which means they have no return value. But I should still be able to invoke them all. When I do use statementToCode or similar I DO get the first of the definitions (in the image function local-definition) but not the rest. I swapped them around and it was always the first one that had code generated.
So I really don't see the issue. In other examples they do virtually nothing but
var branch = Blockly.JavaScript.statementToCode(block, 'STACK');
so why does this not work here?