--
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+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
--
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.
Blockly.Blocks['setintervalwithcount'] = {
init: function() {
this.appendDummyInput()
.appendField("Repeat ")
.appendField(new Blockly.FieldNumber(0, 0, Infinity, 1), "COUNT")
.appendField("times every")
.appendField(new Blockly.FieldNumber(0, 0, Infinity, 0.01), "INTERVAL")
.appendField("seconds");
this.appendStatementInput("STATEMENTS")
.setCheck(null);
this.setPreviousStatement(true, null);
this.setNextStatement(true, null);
this.setColour(230);
this.setTooltip("");
this.setHelpUrl("");
}
};
Blockly.JavaScript['setintervalwithcount'] = function(block) {
var count = block.getFieldValue('COUNT');
var interval = block.getFieldValue('INTERVAL') * 1000; // milliseconds
var statements = Blockly.JavaScript.statementToCode(block, 'STATEMENTS');
// Generate unique variable names
var i = 'i_' + Math.random().toString(36).substr(2, 16);
var timerId = 'timerId_' + Math.random().toString(36).substr(2, 16);
var code = `var ${i} = 0;\nvar ${timerId} = setInterval(function() {\n ${statements}\n\tif(++${i} === ${count}) {\n\t\tclearInterval(${timerId});\n\t}\n}, ${interval});\n`;
return code;
};
var i_sx34cu3paf = 0;
var timerId_0kvwehj324g = setInterval(function() {
//...
if(++i_sx34cu3paf === 4) {
clearInterval(timerId_0kvwehj324g);
}
}, 5000);
--
this.appendDummyInput()
.appendField("Afterwards do ")
this.appendStatementInput("AFTER_LOOP")
.setCheck(null);
Then the users can add statements that should be executed AFTER the repeat loop.
Of cours the second statement input should be optional, so the user can hide it somehow (??) if there is nothing to do afterwards.
Do you think this is more self-explaining ? Or do you have a better idea to solve this?
--
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+u...@googlegroups.com.
for (i = 1; i <= 10; i++) {
var i_sx34cu3paf = 0;
var timerId_0kvwehj324g = setInterval(function() {
//...
if(++i_sx34cu3paf === 4) {
clearInterval(timerId_0kvwehj324g);
}
}, 5000);
}
But then the user needs to be able to select the timer variable name also in the delay block. And then I'm drifting away from your original idea, which was much more self-explaining ;-(
The first line 'run timer ...' seems acceptable to me, however when adding the second line 'count with ...' it could become confusing.
Any suggestions for this, based on your Blockly user experience ?
--
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.
nextStatement
, to make sure it executes after the timer? --
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+u...@googlegroups.com.
await new Promise((resolve, reject) => setTimeout(resolve, 3000));
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.
--
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.