This is something that I think we need to resolve eventually. Right now in Scratch, if you click a running stack, that stack stops. But what happens if it was running a long-running block, like "motor on for 5 secs"? In our current model, the motor would stay on, I think... Perhaps tapping a running stack shouldn't stop it, or we need to think about how to implement stopping it.
Currently, only one field/shadow block is present in the VM's representation. For example, create an addition block. The left field is shown in the tree; the right one is not there.
(e.g., "color touching color" across a thread boundary).
In Scratch 1.0/2.0, this is handled by ensuring that all operations that need to block all threads are actually performed synchronously. So, one way would be to make sure that the reporter doesn't give up the JS execution thread until it gets its answer (while loop?). The other way would be to have a flag on util.yield that specifically disables running other threads until that reporter returns.
How should these be handled in the VM? Should they be done like Scratch 2.0 (where there's an imperative method like allHatsDo), more like Scratch extensions (asynchronous vs. synchronous), or some mix?
It would be great to have a mode of execution where things are stepped by a button in the VM playground. The button would essentially call stepThreads() with a tiny WORK_TIME, to proceed one block per thread every time the button is pushed.
In the long run, it would be good to have single-stepping mode a la Scratch 1.4
If WebWorkers are available, it would be great to launch the VM in a worker thread instead of in the main thread. It would be good to do this as soon as possible, so we make sure our implementation isn't accidentally doing main-thread-only tasks, and so that we get the timing right across the two threads.
In Scratch 2.0, there's a global interpreter flag that tracks whether a block has triggered a sprite's drawn representation to become out-of-date. E.g, a "move 10 steps" block would trigger redraw, but a "set var to 20" wouldn't. The value of this flag determines whether or not a loop yields at the end of a frame (if the interpreter isn't in turbo mode). We need an equivalent flag in scratch-vm, and we can also use something similar to determine whether we should call the renderer's draw method.
To accelerate VM playing and develop, we'd like to create a "VM playground."
This will link to scratch-blocks and pre-load a bunch of blocks. Ideally I'd like to create a small tool to explore the AST, step execution and explore the internal state, etc.
I think we need [repeat until (...)] blocks in ["scratch3_control.js"](https://github.com/LLK/scratch-vm/blob/develop/src/blocks/scratch3_control.js) `'control_repeat_until': this.repeatUntil`?
Until we can implement the VM in a WebWorker, running as much computation as we are seems to be hanging the main UI thread...this is mostly visible when dragging blocks around. It won't make it as perfect as we can, but we could improve it slightly by making the blocks execute for less ms.
These are in index.js currently and have some duplicated code for flyout vs. workspace blocks. Ideally I'd like to refactor it and move it into the Blocks module.
Repeat blocks with values more than zero always run forever, the loopCounter never goes down:
My browser / operating system: Linux, Firefox 50.0, Flash 11.2 (release 202)
We created this infrastructure quickly to try to support the WeDo prototype. I think it should support our thread timing needs, but we'd like to have a discussion about it before we start building on it too deeply, as it's a little bit messy.
Need to figure out how to associate blocks with particular targets. As part of this, it would be good to create the "sprite manager" as per our plans, which will store the master copy of data pertaining to all sprites, including x/y position, current costume, etc., and pass this along to the renderer on every frame.
Some of these names are not like the other. Notably, the "thread stack" is a very different thing from the "block stack." This naming situation has led to awkward situations, like pushing the stack to the stack.
Scratch-blocks is very simple about what stacks are glowed - you just tell it which ones to do and it will do it. We need to build in some smart behavior to the VM for when you are moving around executing blocks, which stacks should be glowed. For example, if you start executing a stack, let the execution point go to the bottom of the stack, and then pull off the bottom, the bottom will still be executing, when the top half is the highlighted one :(
Scratch 2.0 has a bunch of bugs here also so it may be tricky to get right, but important, I think.
Inserting blocks into the middle of the stack doesn't seem to be working correctly. The right things are not being executed, and I suspect it is related to MOVE