@RoboErikG brought up an important point which is during our "purge" of functionality which is unused in Scratch 3.0 we eliminated all of the individual generators. This isn't an issue for Scratch, but does lead to an unused / unmaintained code path which could be useful to potential users of Scratch Blocks. We should add documentation and consider adding some minimal example generators to ensure support in the future.
As a potential user this is exactly what I am interested in. Specifically because I'd like a way to be able to execute the user-created code.
We explored the alternative of using the scratch-vm to run scratch-block code but the VM is a lot more than just executing block-code: engine for running scratch projects. We would like a more flexible integration (a-la blockly) but do want all the lovely scratch styling of the blocks.
The best way to achieve this seems to be adding back the code generators for JS, and then using the JS Interpreter (like the blockly demo). An alternative might be to externalize a subset of the VM, but this seems a lot more complex and unknown.
I found the original commits pulling this code: https://github.com/LLK/scratch-blocks/commit/0c4d175184ffa21da287a37585e01bc7531b5d15
Given how nicely the generators are externalized from the rest of the project it seems putting them back should be mainly reversing that commit. Besides that there may be gaps if blocks were added since then that never got generators.
Any other aspects of adding these back that I might be missing?
So trying this out I ran into an issue: it appears that scratch-blocks has renamed all of the blocks that are used from Blockly. For example, for the && operator Blockly has 'logic_operation' but Blockly has 'operator_and'.
Also, this doesn't seem like a plain old renaming. This can be seen with the above boolean && operation. I guess this is not a technical thing... but a design choice: 1 block with an AND/OR dropdown vs 1 block each.
So really adding code-generation support for Scratch-Blocks... is not simply a matter of putting back the code-generators from Blockly that were pulled... but also actually WRITING the code-generators for ALL the scratch blocks. I will investigate this next week.
I'm assuming scratch-blocks never wrote any code generators for their blocks given its not something scratch needs.
Correct. The crux of the issue is that adding back the ability to generate arbitrary code (by adding the blockly generators/javascript.js, generators/python.js, etc. files) isn't the same as creating generators for each block in the scratch toolbox.
As far as I know the scratch team is not planning to create generators for their blocks. This issue is more a discussion of whether the generator files for various languages will be there if you want to create your blocks with a scratch-style appearance and write your own generators for them.
Scratch's blocks are sufficiently different from the sample blocks that Blockly provides that I wouldn't consider it a renaming. They are just different.
As per discussion with @picklesrus today we have decided to make sure we continue to support generators despite our strong recommendation to use the scratch-vm for most users.
I believe the code part is done. As discussed above, none of the blocks in the scratch set have generators written for them, but a developer can come in and write generators for blocks that they want.
For the documentation side, these are probably the most relevant blockly pages.
https://developers.google.com/blockly/guides/configure/web/code-generators
https://developers.google.com/blockly/guides/create-custom-blocks/generating-code
https://developers.google.com/blockly/guides/create-custom-blocks/operator-precedence
https://developers.google.com/blockly/guides/create-custom-blocks/caching-arguments
@picklesrus Just following up: I think this is probably good enough to get most folks unstuck for now. Thanks!
Most helpful comment
As per discussion with @picklesrus today we have decided to make sure we continue to support generators despite our strong recommendation to use the
scratch-vmfor most users.