I am currently working on a tool to generate Lua code in Blockly to simplify the code of a library.
However, two problems have arisen.
1. When I connect a value block to an If, it doesn't go into a conditional expression.I want to connect a value block with an If so that it enters the conditional expression of the if,(e.g. if <value block generated code> then)
When I connect it with if or while, the code is generated as a variable.
What should I do?
(Some sentences may be incorrect due to the use of translation.)Html Code
Blockly.Blocks['getWidth'] = {
init: function () {
this.appendDummyInput()
.appendField("Text");
this.setInputsInline(true);
this.setOutput(true, null); this.
this.setColour(225); this.
this.setTooltip(""); this.
this.setHelpUrl(""); this.setHelpUrl(""); }
}
}; }
JavaScript Code
lua.luaGenerator.forBlock['getWidth'] = function (block, generator) {
// TODO: Assemble lua into code variable.
var code = 'getWidth()'; //<- Execute and a number will be returned as return value
// TODO: Change ORDER_NONE to the correct strength.
return code;
};
2. How to add end to the tail of a functionIf you place an event block (although it looks like an event block, it is just a function inside) When I place an event block (which is just a function) in a workspace, I want it to look like the following.Currently I am having trouble with the end not being added to the end.
function EventName()
// Code for the connected block
end
--------
HTML Code
Blockly.Blocks['event'] = {
init: function () {
this.appendDummyInput()
.appendField("text");
this.setInputsInline(true);
this.setNextStatement(true, null); this.
this.setColour(0); this.
this.setTooltip(""); this.
this.setHelpUrl(""); this.setHelpUrl(""); }
}
}; }
Javascript Code
Blockly.Blocks['event'] = {
init: function () {
this.appendDummyInput()
.appendField("text");
this.setInputsInline(true);
this.setNextStatement(true, null); this.
this.setColour(0); this.
this.setTooltip(""); this.
this.setHelpUrl(""); this.setHelpUrl(""); }
}
};