From f9b4775c7d962aca7dddae7b187541e58345a20b Mon Sep 17 00:00:00 2001 From: Muffin Date: Tue, 22 Aug 2023 14:42:08 -0500 Subject: [PATCH 1/2] Loop and condition test https://github.com/TurboWarp/scratch-vm/pull/141 --- website/test/loops.js | 72 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 website/test/loops.js diff --git a/website/test/loops.js b/website/test/loops.js new file mode 100644 index 0000000000..75439fb3f0 --- /dev/null +++ b/website/test/loops.js @@ -0,0 +1,72 @@ +// From https://github.com/TurboWarp/scratch-vm/pull/141 +(function (Scratch) { + "use strict"; + + class LoopsAndThings { + getInfo() { + return { + id: "loopsAndThings", + name: "Loops and things test", + blocks: [ + { + opcode: "conditional", + blockType: Scratch.BlockType.CONDITIONAL, + text: "run branch [BRANCH] of", + arguments: { + BRANCH: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 1 + } + }, + branchCount: 3 + }, + { + opcode: "loop", + blockType: Scratch.BlockType.LOOP, + text: "my repeat [TIMES]", + arguments: { + TIMES: { + type: Scratch.ArgumentType.NUMBER, + defaultValue: 10 + } + }, + }, + '---', + { + opcode: "testPromise", + blockType: Scratch.BlockType.REPORTER, + text: "return [VALUE] in a Promise", + arguments: { + VALUE: { + type: Scratch.ArgumentType.STRING, + defaultValue: '' + } + } + } + ] + }; + } + + conditional({BRANCH}, util) { + return Scratch.Cast.toNumber(BRANCH); + } + + loop({TIMES}, util) { + console.log(TIMES, util.stackFrame.loopCounter); + const times = Math.round(Scratch.Cast.toNumber(TIMES)); + if (typeof util.stackFrame.loopCounter === "undefined") { + util.stackFrame.loopCounter = times; + } + util.stackFrame.loopCounter--; + if (util.stackFrame.loopCounter >= 0) { + return true; + } + } + + testPromise({VALUE}) { + return Promise.resolve(VALUE); + } + } + + Scratch.extensions.register(new LoopsAndThings()); +})(Scratch); \ No newline at end of file From bc5de7b746272ea3158287db948529a0eecb080a Mon Sep 17 00:00:00 2001 From: Muffin Date: Tue, 22 Aug 2023 14:43:13 -0500 Subject: [PATCH 2/2] Remove debug stuff --- website/test/loops.js | 1 - 1 file changed, 1 deletion(-) diff --git a/website/test/loops.js b/website/test/loops.js index 75439fb3f0..ae1bf2f6c3 100644 --- a/website/test/loops.js +++ b/website/test/loops.js @@ -52,7 +52,6 @@ } loop({TIMES}, util) { - console.log(TIMES, util.stackFrame.loopCounter); const times = Math.round(Scratch.Cast.toNumber(TIMES)); if (typeof util.stackFrame.loopCounter === "undefined") { util.stackFrame.loopCounter = times;