Implement logic_equals, if blocks

This commit is contained in:
Tim Mickel 2016-06-10 10:36:05 -04:00
parent 506e9c32be
commit ca68c55d57
2 changed files with 30 additions and 9 deletions

View file

@ -15,14 +15,15 @@ Scratch3ControlBlocks.prototype.getPrimitives = function() {
'control_repeat': this.repeat,
'control_forever': this.forever,
'control_wait': this.wait,
'control_if': this.if,
'control_stop': this.stop
};
};
Scratch3ControlBlocks.prototype.repeat = function(argValues, util) {
Scratch3ControlBlocks.prototype.repeat = function(args, util) {
// Initialize loop
if (util.stackFrame.loopCounter === undefined) {
util.stackFrame.loopCounter = parseInt(argValues.TIMES);
util.stackFrame.loopCounter = parseInt(args.TIMES);
}
// Decrease counter
util.stackFrame.loopCounter--;
@ -32,15 +33,26 @@ Scratch3ControlBlocks.prototype.repeat = function(argValues, util) {
}
};
Scratch3ControlBlocks.prototype.forever = function(argValues, util) {
Scratch3ControlBlocks.prototype.forever = function(args, util) {
util.startSubstack();
};
Scratch3ControlBlocks.prototype.wait = function(argValues, util) {
Scratch3ControlBlocks.prototype.wait = function(args, util) {
util.yield();
util.timeout(function() {
util.done();
}, 1000 * argValues.DURATION);
}, 1000 * args.DURATION);
};
Scratch3ControlBlocks.prototype.if = function(args, util) {
// Only execute one time. `if` will be returned to
// when the substack finishes, but it shouldn't execute again.
if (util.stackFrame.executed === undefined) {
util.stackFrame.executed = true;
if (args.CONDITION) {
util.startSubstack();
}
}
};
Scratch3ControlBlocks.prototype.stop = function() {

View file

@ -13,17 +13,26 @@ function Scratch3OperatorsBlocks(runtime) {
Scratch3OperatorsBlocks.prototype.getPrimitives = function() {
return {
'math_number': this.number,
'math_add': this.add
'text': this.text,
'math_add': this.add,
'logic_equals': this.equals
};
};
Scratch3OperatorsBlocks.prototype.number = function(args) {
Scratch3OperatorsBlocks.prototype.number = function (args) {
return Number(args.NUM);
};
Scratch3OperatorsBlocks.prototype.add = function(args) {
Scratch3OperatorsBlocks.prototype.text = function (args) {
return String(args.TEXT);
};
Scratch3OperatorsBlocks.prototype.add = function (args) {
return args.NUM1 + args.NUM2;
};
Scratch3OperatorsBlocks.prototype.equals = function (args) {
return args.VALUE1 == args.VALUE2;
};
module.exports = Scratch3OperatorsBlocks;