From b29cb0e7dbfe391c99f7502844b9d2f3c2fa6d6b Mon Sep 17 00:00:00 2001 From: valadaptive Date: Fri, 14 Jun 2024 17:23:23 -0400 Subject: [PATCH] Implement control_while This makes Crystal Seeker playable --- src/blocks.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/blocks.ts b/src/blocks.ts index ae7bec2..d656104 100644 --- a/src/blocks.ts +++ b/src/blocks.ts @@ -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: {