Create a generic 'Pause Until' block

Hello!

I am trying to create a ‘Pause Until’ block that can take a function with a boolean return value and pauses until it turn true. Makecode for the EV3 has such a block but not for micro:bit. I can create the function but the corresponding block does not look as it should. Specifically it does not have the ‘pointy’ parameter placeholder where a boolean input can be placed. The code looks like this:

    //% block="Pause until %condition || timeout %timeOut"
    export function pauseMeUntil(condition: () => boolean, timeOut?: number): void {
        if (!condition || condition()) return; // optimistic path
        if (!timeOut) timeOut = 0;
        control.__queuePollEvent(timeOut, condition, undefined);
    }

It should look like this:
image

but it actually looks like this:
image

Any ideas how I could get this to work?
Thanks!
Michael

2 Likes

@mpoelzl this actually isn’t possible to do from an extension. The pause until block is special and can only be enabled by turning it on in the pxtarget.json of pxt-microbit. With that being said, I’m actually surprised that we didn’t already enable this in the micro:bit editor; I don’t think we ever discussed it on the team so this might have just been an oversight on our part…

You should open an issue for it here:

I personally don’t see an issue with adding it to the default toolbox, but I’m sure there will be some discussion over what category to put it in.

3 Likes

Thank you for the quick reply and the extra info. It would be great to have this block for the younger learners as it greatly simplifies a series of robot drive tasks (no need for loops).

I have created an issue on GitHub.

2 Likes