Weird Block Formatting Breaks Code

I’m creating a custom block with quite weird formatting and whenever I go to blocks from javascript the function(){ } parameter disappears.


This is the shape of block:
Screenshot 2023-05-29 at 19-49-51 Microsoft MakeCode Arcade
This is the code for the block:

    //% value.defl=function () { }
    //% block="JSON"
    //% handlerStatement=1
    export function json(handler: () => void): {} {
        return {}
    }

Once I go to the blocks tab, the code goes from this: custom.json(function() { }) to this: custom.json()

It also gives me this error:

Line 1: Expected 1 arguments, but got 0.

This is mainly for the MakeCode team, but if anyone else could help me that would be great!

2 Likes

Unfortunately, this is not supported; blocks that take function parameters are not allowed to return values.

Out of curiosity, what’s your scenario for this?

2 Likes

I’m making an extension that lets you create a json object with blocks like this:
98b6e8cc1357170f

ah, makes sense! Unfortunately, I don’t think we have plans to add this right now but you can open an issue here: https://github.com/microsoft/pxt-arcade/issues

2 Likes

Why are you on Code.org?