I'm am making an Blockly application that generates brightscript code. How do I fix the Blockly error below.
I tried many things, all gave worse results.
<html>
<head>
<title>ProgrammableRokuChannel</title>
<script src="https://unpkg.com/blockly/blockly.min.js"></script>
<script src="https://unpkg.com/blockly/blocks.min.js"></script>
<script src="https://unpkg.com/blockly/javascript.min.js"></script>
<script src="https://unpkg.com/blockly/generators/brightscript.js"></script>
</head>
<body>
<button id="downloadButton">Download Code</button>
<textarea id="code-preview" rows="10" cols="50"></textarea>
<div id="blocklyDiv" style="height: 480px; width: 600px;"></div>
<script>
// Define the BrightScript code generation functions
Blockly.BrightScript = new Blockly.Generator('BrightScript');
Blockly.BrightScript['controls_if'] = function(block) {
// Generate BrightScript code for an "if" block
var value_condition = Blockly.BrightScript.valueToCode(block, 'CONDITION', Blockly.BrightScript.ORDER_NONE);
var statements_thenBranch = Blockly.BrightScript.statementToCode(block, 'THEN');
var code = 'if ' + value_condition + ' then\n' + statements_thenBranch + 'end if\n';
return code;
};
Blockly.BrightScript['text_print'] = function(block) {
// Generate BrightScript code for a "print" block
var value_text = Blockly.BrightScript.valueToCode(block, 'TEXT', Blockly.BrightScript.ORDER_NONE);
var code = 'print ' + value_text + '\n';
return code;
};
Blockly.Blocks['text_input'] = {
init: function() {
this.appendDummyInput()
.appendField("input text:")
.appendField(new Blockly.FieldTextInput("default value"), "INPUT");
this.setOutput(true, "String");
this.setColour(160);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.BrightScript['text_input'] = function(block) {
var text_input = block.getFieldValue('INPUT');
var code = '"' + text_input + '"';
return [code, Blockly.BrightScript.ORDER_NONE];
};
// Add the BrightScript code generator to the workspace
const toolbox = `
<xml xmlns="http://www.w3.org/1999/xhtml">
<category name="Logic">
<block type="controls_if"></block>
</category>
<category name="Text">
<block type="text_print"></block>
<block type="text_input"></block>
</category>
</xml>
`;
const workspace = Blockly.inject('blocklyDiv', {toolbox: toolbox});
// Update the preview whenever the workspace changes
function updatePreview() {
var code = Blockly.BrightScript.workspaceToCode(workspace);
document.getElementById('code-preview').value = code;
}
workspace.addChangeListener(updatePreview);
// Update the preview when the page loads
updatePreview();
// Download the code when the button is clicked
const downloadButton = document.getElementById('downloadButton');
downloadButton.addEventListener('click', function() {
const code = Blockly.BrightScript.workspaceToCode(workspace);
const blob = new Blob([code], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.download = 'code.brs';
link.href = url;
link.click();
});
</script>
</body>
</html>
I tried many things and all made code worse.
I'm hoping to get some advice on how to fix my code and get it working correctly. Any help or suggestions would be greatly appreciated!
Failed to load resource: the server responded with a status of 404 ()
unpkg.com/blockly@9.2.1/blocks.min.js:1 Failed to load resource: the server responded with a status of 404 ()
unpkg.com/blockly@9.2.1/javascript.min.js:1 Failed to load resource: the server responded with a status of 404 ()
5all.js:27 Uncaught TypeError: Expecting valid order from block: text_print
at $.CodeGenerator$$module$build$src$core$generator.valueToCode (all.js:27:11)
at Blockly.BrightScript.text_print ((index):28:41)
at $.CodeGenerator$$module$build$src$core$generator.blockToCode (all.js:27:11)
at $.CodeGenerator$$module$build$src$core$generator.workspaceToCode (all.js:27:11)
at updatePreview ((index):67:35)
at WorkspaceSvg$$module$build$src$core$workspace_svg.fireChangeListener (all.js:27:11)
at fireNow$$module$build$src$core$events$utils (text.js:278:74)
/favicon.ico:1 Failed to load resource: the server responded with a status of 404 (Not Found)
DevTools failed to load source map: Could not load content for chrome-extension://gighmmpiobklfepjocnamgkkbiglidom/browser-polyfill.js.map: System error: net::ERR_FILE_NOT_FOUND
DevTools failed to load source map: Could not load content for chrome-extension://bmnlcjabgnpnenekpadlanbbkooimhnj/browser-polyfill.js.map: System error: net::ERR_BLOCKED_BY_CLIENT