ScratchData LogoScratchData
Back to _nix's profile

Sequencer Continuation Loop

_N_nix•Created October 31, 2021
Sequencer Continuation Loop
0
0
16 views
View on Scratch

Description

Very simple control loop which keeps track of multiple "threads" of sequenced broadcasts, cycles through and runs the top broadcast for each thread one by one, and provides a useful interface (global variables at end of "when I receive" script) for pushing the next message-plus-continuation. The goal here is to find a way to support recursive broadcasts, i.e. a chain which might look like this: 1) bc1, with a condition met, broadcasts bc2 (& wait) 2) bc2 does something 3) bc2 broadcasts bc1 (& wait) 4) bc1, no condition met, broadcasts bc3 (& wait) 5) bc3 does something 6) NEWER bc1 thread does something 7) ORIGINAL bc1 thread does something (Note steps 2-3 are unnecessary in the base case. It's only there to demonstrate indirect recursion. Direct recursion would run into the same problem of...) The issue is, one script can't run twice as a single thread. See this old discussion topic for investigations back in 2018: https://scratch.mit.edu/discuss/topic/305574/ If you were to program the above sequence, you'd find the second broadcast of bc1 "overwrites" the original, halting execution at step 1 ("and wait") and preventing ever reaching step 7 (step 6 is still reached though, because the second broadcast isn't overwritten and runs to completion). The example programmed using the sequencer in this project demonstrates multithreading rather than recursion (as I think multithreading is a more important aspect to show works properly)—but because it uses continuation-passing style (or my awful approximation of it :P) rather than literally leaving a script active in the background, recursion should work properly as a given. *remixes to test lol*

Project Details

Project ID592858259
CreatedOctober 31, 2021
Last ModifiedOctober 31, 2021
SharedOctober 31, 2021
Visibilityvisible
CommentsAllowed