Discuss Scratch

B1j2754
Scratcher
78 posts

Scratch Procedure Argument Defaults

After messing around with argument defaults for procedures, I've finally found out how to use them.
For reference, in Scratch's json, there exists an array of default values for each argument in a procedure. I originally thought this was unused, until I saw a project by nembence (Project here), which seems to use hidden reporters. With this in mind, I knew that Scratch was indeed looking at the reporters, but didn't quite know when or why.

Further in the project, after looking through the json, there was an interesting quirk that was used: arguments that exist in the argumentnames and argumentids but aren't in the proccode just default to their argumentdefault value.

Through experimentation, empty boolean blocks do actually listen to their argumentdefaults value. Though confusing at first, their proccall block reveals that they just don't have a value when empty, appearing as a darker shade of the my blocks colors. Using this, we can actually apply a very similar idea. By removing the inputs entirely (think providing `()` instead of `(“”)`), we can also get blocks to appear like this. Loading this edited procall back into scratch shows us that the inputs are now truly empty, triggering the undefined check in the code.

An interesting note: after blocks are put inside inputs that have been removed, instead of being [1, ] as they usually are in the json, they become [2, ], which I previously thought was reserved for boolean/substacks. I guess it is also used in this case, so not sure if there is a general rule anymore. If used in the [2, ] notation, when a reporter block is removed, it will maintain its “true empty” state of `()`

This can also just be achieved just setting the inputs to

Previous:


Hacked for defaults with removal:


Hacked for defaults with null:


Procdef for reference:

Powered by DjangoBB