Skip to content

Commit 11a10e4

Browse files
committed
extendable if-else blocks
1 parent 1fd8fc7 commit 11a10e4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/blocks/scratch3_control.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Scratch3ControlBlocks {
3232
control_wait_until: this.waitUntil,
3333
control_if: this.if,
3434
control_if_else: this.ifElse,
35+
control_if_extendable: this.ifExtendable,
36+
control_if_else_extendable: this.ifElseExtendable,
3537
control_stop: this.stop,
3638
control_create_clone_of: this.createClone,
3739
control_delete_this_clone: this.deleteClone,
@@ -137,6 +139,27 @@ class Scratch3ControlBlocks {
137139
}
138140
}
139141

142+
ifExtendable (args, util) {
143+
const argCount = args.BRANCHES;
144+
for (let i = 0; i < argCount; i++) {
145+
if (Cast.toBoolean(args[`BRANCHES_${i}_CONDITION`])) {
146+
util.startBranch(`BRANCHES_${i}_BRANCH`);
147+
return;
148+
}
149+
}
150+
}
151+
152+
ifElseExtendable (args, util) {
153+
const argCount = args.BRANCHES;
154+
for (let i = 0; i < argCount; i++) {
155+
if (Cast.toBoolean(args[`BRANCHES_${i}_CONDITION`])) {
156+
util.startBranch(`BRANCHES_${i}_BRANCH`);
157+
return;
158+
}
159+
}
160+
util.startBranch('ELSE');
161+
}
162+
140163
stop (args, util) {
141164
const option = args.STOP_OPTION;
142165
if (option === 'all') {

0 commit comments

Comments
 (0)