-
Notifications
You must be signed in to change notification settings - Fork 419
Proof of Concept: Custom reporters #8674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Proof of Concept: Custom reporters #8674
Conversation
also begin serializing so that scratch doesn't die without the addon
This reverts commit 6ed9dcf to temporarily allow testing on the spork branch of scratch-editor (which hasn't updated the react version yet)
|
I have updated the code to use the new blockly/spork. I have dropped the old code using the old blockly because they diverge enough that it would be difficult to maintain both. I had to revert #8611 to be able to test on spork; this will need to be unreverted at some point in the future. It should be noted that some things aren't quite on par with the old blockly implementation just yet. |
3decf20 to
177e3ee
Compare
recolor custom blocks only “splices”, calls into methods like rearrange custom blocks unfortunately completely overrides |
|
@FlamedDogo99 thanks for the heads up - it sounds like there shouldn't be any compatibility problems with the procedures_prototype blocks as I only patch on top of existing methods for that particular block. There might be issues with addition of extra buttons but that should be solvable with a shared space or similar. I will of course do some proper testing at some point in the future. |
|
one note, because goboscript has this issue: |
|
@faretek1 thank you for pointing this out - I hadn't considered this. I think at the moment it should behave as expected for addon users, but definitely won't transpile sensibly. |
|
Another thing to think about: what should be done about custom reporters placed inside of a hat block? e.g. |
It might be possible to use Blockly's system of return types/connection checks to enforce this. |
This would resolve #8427 if finished and merged.
Related: #7475; suggestion in community server; discussion in dev server (scroll down for more technical discussion).
I don't expect that this will ever make it into the main repository, but it'd be cool if it did.
Although this is marked as a draft, feedback would be appreciated at any stage, especially in relation to the broad implementation.
Changes
This adds a new "custom reporters" addon that allows users to create custom blocks that return values. These are patched in the VM to be executed correctly, and then transpiled at serialisation to valid scratch blocks.
These blocks are not fully compatible with TurboWarp's custom reporters. I think they share the same opcodes in the internal representation, but beyond that there are very few similarities, as TurboWarp is able to integrate the expected behaviour without worrying about compatibility with vanilla scratch.
This is a proof of concept, and as such it is very rough around the edges and not at all in a state where it is usable for general purposes. I will list problems that I am aware of in a later section; it should be noted that currently the addon is marked as 'enabled by default' for my own testing purposes.
The custom block editor now looks like this:

There are currently two modes of transpilation; these are not necessarily good transpilation schemes but they work well in many common cases. In each transpiler mode, the VM is patched to execute the custom reporters in the way that they would be executed when transpiled to vanilla scratch, rather than being executed in the way you might naively expect (e.g. if used to TurboWarp's custom reporters).
Variable transpilation mode
This sets a variable to the return value. This works fine for non-recursive functions, or recursive functions that use the value of a recursive call at most once per stack block.
With addon enabled:

With addon disabled:

(script positions were changed manually)
List (no GC) transpilation mode
This appends the return value to a list. The list is never emptied (hence the "no GC" naming). In theory, this works fine for any sort of recursive function, provided that it is run without refresh and never triggers the warp timer (these restrictions apply to the variable transpiler mode as well). In practice, at the moment I don't think nested recursive calls will be applied correctly.
With addon enabled:

With addon disabled:

Reason for changes
The variable workaround for custom reporters seems to be well-known and well-used among more advanced scratchers. Making it easier to do this sort of thing might be nice for some people. Custom reporters seemed to be received quite well with TurboWarp, which suggests that there is an audience for this (although perhaps they'd rather use TurboWarp's better implementation of it regardless). Perhaps more importantly, it's interesting to see how much we can extend the language without breaking things too badly.
Tests
Leaving empty for now, as it is easier to list things that don't work correctly than those that do.
Known issues
Cannot read properties of null (reading 'FIELD_BORDER_RECT_RADIUS')while <>,repeat until <>andfor each [i v] in ()don't currently re-evaluate custom reporters each iteration (they should)There is probably more that I am forgetting, or have yet to discover.
Future work
Open questions
when loudness > (something)?Todo before merging (if ever)