mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-01-11 10:39:56 -05:00
Add implementation for while
This commit is contained in:
parent
27d053acff
commit
c57d0c94eb
1 changed files with 10 additions and 1 deletions
|
@ -17,6 +17,7 @@ class Scratch3ControlBlocks {
|
||||||
return {
|
return {
|
||||||
control_repeat: this.repeat,
|
control_repeat: this.repeat,
|
||||||
control_repeat_until: this.repeatUntil,
|
control_repeat_until: this.repeatUntil,
|
||||||
|
control_while: this.repeatWhile,
|
||||||
control_for_each: this.forEach,
|
control_for_each: this.forEach,
|
||||||
control_forever: this.forever,
|
control_forever: this.forever,
|
||||||
control_wait: this.wait,
|
control_wait: this.wait,
|
||||||
|
@ -56,12 +57,20 @@ class Scratch3ControlBlocks {
|
||||||
|
|
||||||
repeatUntil (args, util) {
|
repeatUntil (args, util) {
|
||||||
const condition = Cast.toBoolean(args.CONDITION);
|
const condition = Cast.toBoolean(args.CONDITION);
|
||||||
// If the condition is true, start the branch.
|
// If the condition is false (repeat UNTIL), start the branch.
|
||||||
if (!condition) {
|
if (!condition) {
|
||||||
util.startBranch(1, true);
|
util.startBranch(1, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repeatWhile (args, util) {
|
||||||
|
const condition = Cast.toBoolean(args.CONDITION);
|
||||||
|
// If the condition is true (repeat WHILE), start the branch.
|
||||||
|
if (condition) {
|
||||||
|
util.startBranch(1, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
forEach (args, util) {
|
forEach (args, util) {
|
||||||
const variable = util.target.lookupOrCreateVariable(
|
const variable = util.target.lookupOrCreateVariable(
|
||||||
args.VARIABLE.id, args.VARIABLE.name);
|
args.VARIABLE.id, args.VARIABLE.name);
|
||||||
|
|
Loading…
Reference in a new issue