Macros! TW blocks that compile to scratchblocks #1592
Replies: 2 comments 3 replies
-
I've though about similar things in the past, however the Scratch Team likely wouldn't take to fondly to it. Specifically, there's a clause in the Terms of Use (section 4.4) that prohibits uploading projects that cannot be run on Scratch. It's different for projects that simply aren't powerful enough for Scratch, given with enough time and sacrifice they can run on the website, however designing projects specifically to run in TurboWarp and not Scratch would definitely be against TOS. |
Beta Was this translation helpful? Give feedback.
-
I feel like a much better way to describe this would be that they want to add blocks that make building projects easier, such as "Multiply x by 5," and appear that way in the editor, but when saved it saves as "Set x to (x)(5)." Also potentially have a few ways to "Convert" certain extension blocks to a scratch block. As much as I've wanted this a TON, it's really something you just have to do manually. It's impossible to convert most extension code into scratch code without changing it entirely, and that's something up to the user's discretion. Maybe one day I can understand the SB3 jsons enough to code one for myself, but that doesn't guarantee that it will work for others, and I'm 99% sure that before anything gets added to turbowarp has to work for everyone, and no matter how customizable you make it, it's too much work to make it work for everyone. |
Beta Was this translation helpful? Give feedback.
-
Macros!
Hello, I’m new here, and I am curious as to if there is (or could soon be) a way to have macros in extensions!
TL;DR
Plz add the ability to put special blocks which will turn into scripts at compile time into custom extensions. Thanks!
THE END
Introduction
Basically, say I wanted to create the following blocks for a custom extension:
I know that these are already featured in existing TurboWarp extensions. However, I want to be able to use these custom TurboWarp blocks in Scratch. Fortunately, there are pretty easy workarounds for these blocks:
However, nobody wants to have to make their code into an unreadable mess such as this:
Rant
Yes, I know strings exist. However, this is just a very simple example here, and there are plenty more. Additionally, writing the word "true" actually behaves differently than the actual boolean true, and writing the number 1 is still kind of unreadable. But I did not come here to argue with you about the usefulness of this example anyway. >:(
What I’m proposing is, there should be a way to have TurboWarp blocks be automatically converted to their Scratch counterparts at compile time.
What a Macro Is
Yes, we have "My Blocks", but they can be limiting in functionality, and macros are a whole different concept. You see, a custom block is a script which executes at runtime, its code being referenced by other scripts. A macro, on the other hand, is a script which runs at compile time. It produces blocks which are injected into the script wherever the macro is being used. The macro is not included in the script, but rather the blocks that the macro produces are. Macros, at their most basic, are simply a shorthand way of writing blocks or scripts, but with some custom logic, they can be much more than that. Macros are really just extension blocks that turn into ordinary scratch blocks, which can then be run by TurboWarp, and better yet Scratch.
Uses
Macros have a GREAT potential for projects. Some use cases include:
Yes, I know that this sounds largely like a convenience feature so far, but I encourage you to read to the end, as macros can actually be quite a powerful tool.
Examples
Simple Example
Here’s one of the simpler examples:
scratchblocks
The macro shown off above would be a shorthand way of multiplying a variable by a certain amount. Doing this with My Blocks would be no easy feat, as you cannot programmatically determine which variable to set in ordinary Scratch. However, since macros run at compile time rather than at runtime, using some extra JavaScript, the macro can magically transform itself into ordinary block code based off of its arguments before it gets sent to the scratch-vm. Do you see what I’m getting at now??? :P
Complex Example
But macros can do WAY more than just that. Here’s some more complex examples:
<insert some more complex examples here because I’m too lazy to put them here… sorry! ZzzZZZzzZz… I’m tired, OK?>
For real though, the possibilities with this are great. For example, one could program a reporter macro that fetches a file from a server and converts it into a format that your project can use at runtime. Or, one could create a macro for checking the type of a value. OR, you could even make a macro of macros. WHO KNOWS?!?!?!?
I’ve spent a lot of time writing this, OK? Gimme a break…
There are a million other examples that I could give you, but I think that you should be getting the point by now. :>
Insertions
It would be cool if macros could also add statements around them, like so:
This macro asks the user for confirmation as a boolean. To ask the user, it inserts an
ask () and wait
block before the statement that the macro was used in. This allows for more complex reporter macros with multiple steps to them!Implementation
I think that macros could be added in one or more of the following ways:
I think that the first and third options, specifically the first (adding additional options for macros to custom extensions) would be the most viable and practical. A macro would be defined using JavaScript in a similar way to an ordinary block, the main difference being its logic would be called at compile time, and it would have to somehow be able to produce the "compiled" code for itself (or perhaps even modify the code around it for more complex macros). This could require some major reworking, however I’m sure that if anyone can do it, it’s you. :D
There may have to be a separate option when exporting a project from TurboWarp so that one can choose whether or not to download the file with the macros included in it or with the macros compiled. It’s clear that a lot would have to happen to get macros added into TurboWarp, but I hope that we can iron all that stuff out in order to create an amazing, much-needed (well, maybe you didn’t) original (don’t quote me on that) feature that will greatly change the idea of block-programming as we know it!
Notes
Conclusion
Adding macros to TurboWarp would create new and exciting possibilities for Scratch projects, and would open the door to a whole new level of complexity in what started as a simple block-based programming language. I am exhausted after writing all of this, so I’ll leave the rest of the discussion to you guys. I am excited to hear what everybody has to say about this, and thanks for reading. :]
…
Thank you for coming to my TED Talk.
Beta Was this translation helpful? Give feedback.
All reactions