Blockly.Blocks['wait'] = { init: function() { this.appendDummyInput() .appendField("wait 2 second"); this.setInputsInline(false); this.setPreviousStatement(true, null); this.setNextStatement(true, null); this.setColour(230); this.setTooltip(''); this.setHelpUrl(''); }};
Blockly.JavaScript['wait'] = function(block) { // TODO: Assemble JavaScript into code variable. //var code = 'window.setTimeout(3000);'; //var code = 'if (5==3) alert(3232);'; //var code = 'prompt(321);'; var code = 'var ms = 2000;ms += new Date().getTime();while (new Date() < ms) { };';
return code;};
function runCode() { // Generate JavaScript code and run it. var code = Blockly.JavaScript.workspaceToCode(workspace); window.LoopTrap = 1000; //Blockly.JavaScript.INFINITE_LOOP_TRAP = 'if (--window.LoopTrap == 0) throw "Infinite loop.";\n'; Blockly.JavaScript.INFINITE_LOOP_TRAP = null; try { eval(code); } catch (e) { alert(e); }
} function initApi(interpreter, scope) { // Add an API function for the alert() block. var wrapper = function(text) { text = text ? text.toString() : ''; return interpreter.createPrimitive(alert(text)); }; interpreter.setProperty(scope, 'alert', interpreter.createNativeFunction(wrapper)); /* wrapper = function(text) { text = text ? text.toString() : ''; return interpreter.createPrimitive(wait(text)); }; interpreter.setProperty(scope, 'wait', interpreter.createNativeFunction(wrapper));*/ // Add an API function for the prompt() block. wrapper = function(text) { text = text ? text.toString() : ''; return interpreter.createPrimitive(prompt(text)); }; interpreter.setProperty(scope, 'prompt', interpreter.createNativeFunction(wrapper)); }
function runCode() { // Generate JavaScript code and run it. var code = Blockly.JavaScript.workspaceToCode(workspace); alert(code); myInterpreter = new Interpreter(code,initApi); myInterpreter.run();
}--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
function runCode() { if (!myInterpreter) { // First statement of this code. // Clear the program output. resetStepUi(true); runButton.disabled = 'disabled';
// And then show generated code in an alert. // In a timeout to allow the outputArea.value to reset first. setTimeout(function() { alert('Ready to execute the following code\n' + '===================================\n' + latestCode);
// Begin execution highlightPause = false; myInterpreter = new Interpreter(latestCode, initApi); runner = function() { if (myInterpreter) { var hasMore = myInterpreter.run(); if (hasMore) { // Execution is currently blocked by some async call. // Try again later. setTimeout(runner, 10); } else { // Program is complete. outputArea.value += '\n\n<< Program complete >>'; resetInterpreter(); resetStepUi(false); } } }; runner(); }, 1); return; }To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+unsubscribe@googlegroups.com.