我是一名网络开发人员,正在尝试使用 Google Blockly 开发迷宫游戏。
我在这里感到震惊,当我尝试运行它时,我有块,它工作正常,但问题是它没有突出显示当前正在执行的函数。
这是理解的代码,我有这个块代码:
Blockly.Blocks['move_forward'] = {
init: function() {
this.appendDummyInput()
.appendField("move forward");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(290);
this.setTooltip('');
this.setHelpUrl('http://www.example.com/');
}
};
Blockly.Blocks['turn_left'] = {
init: function() {
this.appendDummyInput()
.appendField("turn")
.appendField(new Blockly.FieldDropdown([["left", "l"], ["right", "r"]]), "NAME");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(290);
this.setTooltip('');
this.setHelpUrl('http://www.example.com/');
}
};
Blockly.Blocks['turn_right'] = {
init: function() {
this.appendDummyInput()
.appendField("turn")
.appendField(new Blockly.FieldDropdown([["right", "r"], ["left", "l"]]), "NAME");
this.setPreviousStatement(true);
this.setNextStatement(true);
this.setColour(290);
this.setTooltip('');
this.setHelpUrl('http://www.example.com/');
}
};
and this is related to Blockly javascript
Blockly.JavaScript['move_forward'] = function(block) {
// TODO: Assemble JavaScript into code variable.
// var code = 'moveForward(); \n';
return 'moveForward(\'block_id_' + block.id + '\');\n';
};
Blockly.JavaScript['turn_left'] = function(block) {
var dropdown_name = block.getFieldValue('NAME');
// TODO: Assemble JavaScript into code variable.
// var code = 'turnLeft();\n';
return 'turnLeft(\'block_id_' + block.id + '\');\n';
};
Blockly.JavaScript['turn_right'] = function(block) {
var dropdown_name = block.getFieldValue('NAME');
// TODO: Assemble JavaScript into code variable.
// var code = 'turnRight();\n';
return 'turnRight(\'block_id_' + block.id + '\');\n';
};
I have moveForward(), turnLeft(), turnRight() functions.
var myInterpreter = null;
function interpret(){
var code = Blockly.JavaScript.workspaceToCode(workspace);
myInterpreter = new Interpreter(code, initApi);
Blockly.JavaScript.STATEMENT_PREFIX = 'highlightBlock(%1);\n';
Blockly.JavaScript.addReservedWords('highlightBlock');
console.log(myInterpreter);
myInterpreter.run();
}
function initApi(interpreter, scope){
var wrapper;
wrapper = function(id) {
moveForward(0);
};
interpreter.setProperty(scope, 'moveForward',
interpreter.createNativeFunction(wrapper));
wrapper = function(id) {
turnLeft(1);
};
interpreter.setProperty(scope, 'turnLeft',
interpreter.createNativeFunction(wrapper));
wrapper = function(id) {
turnRight(2);
};
interpreter.setProperty(scope, 'turnRight',
interpreter.createNativeFunction(wrapper));
}
如何编写解释器步骤代码,我还需要突出显示当前在 Blockly 中执行的任何函数。
请帮助解决这个问题。