Skip to content

Commit

Permalink
Implement control_while
Browse files Browse the repository at this point in the history
This makes Crystal Seeker playable
  • Loading branch information
valadaptive committed Jun 14, 2024
1 parent cb29e7a commit b29cb0e
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,22 @@ export const control_repeat_until = new ProtoBlock({
colorCategory: 'control',
});

export const control_while = new ProtoBlock({
opcode: 'control_while',
inputs: {
CONDITION: BooleanInput,
SUBSTACK: StackInput,
},
execute: function* ({CONDITION, SUBSTACK}, ctx) {
// Note that we can't use evaluateFast here because it's not re-entrant!
while (toBoolean(yield* ctx.evaluate(CONDITION))) {
yield* ctx.evaluate(SUBSTACK);
yield;
}
},
colorCategory: 'control',
});

export const control_stop = new ProtoBlock({
opcode: 'control_stop',
inputs: {
Expand Down

0 comments on commit b29cb0e

Please sign in to comment.