microsoft / pxt-microbit

A Blocks / JavaScript code editor for the micro:bit built on Microsoft MakeCode
https://makecode.microbit.org
Other
726 stars 638 forks source link

Create a generic ‘Pause Until’ block for micro-bit (like the block in Makecode for EV3) #5919

Open mpoelzl opened 2 months ago

mpoelzl commented 2 months ago

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 Makecode for micro:bit.

image

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.

As discussed here it is something that already exists and could be added: https://forum.makecode.com/t/create-a-generic-pause-until-block/30448

Would it be possible to make this block availble in Makecode for micro:bit?

Thank you!

riknoll commented 2 months ago

I brought this up with the team, and opinions were torn on whether to add this to the toolbox; the main concern was that adding another block to the default toolbox might be overwhelming. We also discussed where to put it if we were to add it, with the main suggestions being the basic category (which is where the pause block is), loops (which is where it is in our other editors, somewhat arbitrarily), or control (which has the benefit of being in the "advanced" section and has similar blocks already)

Personally, I prefer control since it's out of the way and also is where we put the other pause/wait variants, including this one:

image

@microbit-carlos @jaustin @Jaqster would love to hear feedback on this

mpoelzl commented 2 months ago

Thanks for the feedback! Personally I would argue for adding it to the basic category. I appreciate the concern with regards to "block overload" but I think especially for younger users this would greatly simplify sequence tasks which would otherwise need some form of 'pause loops'. With this in mind the basic category would be most helpful.

But in the end I would be grateful to have it, regardless of category!

THEb0nny commented 1 month ago

@riknoll the pause until block in ev3 is in cycles, which is logical, since it essentially defines a loop while that checks the event...

microbit-carlos commented 1 month ago

To make sure I understand this specific block:

riknoll commented 1 month ago

i believe it is functionally equivalent to the while loop example you provide. the only advantage is, as you said, better wording plus only needing one block vs three

mpoelzl commented 1 month ago

Hello! Yes, the while loop does provide the same functionality. The requests to add this new block is really to make the concept more accessible for the younger kids. We find that having to add the while loop and a 'not' logic is a big distraction when we really want to concentrate on the condition itself. Often we ask the kids to follow a series of instructions like:

A 'Pause Until' block would make this kind of code really easy and clean.

Thanks!

mpoelzl commented 6 days ago

Hello! Are there any more thoughts on this? As mentioned above I think it would be a great addition for younger learners.

In any case, if the concern is that too many blocks are exposed i the standard toolbox then I would also be very happy to have it in the advance section.

jaustin commented 5 days ago

Hi @mpoelzl are you working with students inside a context where you are able to share code with them in advance? If so, you could make this a custom block inside the pre-shared example.

Another option would be to make this a small standalone extension

These have the upside of making the code available to you, but the downside that if you share example code that includes this block, students may later fail to find it when using Makecode without your example. If you publish an extension you can show them how to add it, but that is probably more complicated than just sharing the blocks.

OTOH, it's also a nice opportunity to introduce students to functions.

If you would like to express this as a custom block or in an extension, I'm happy to help you do that.

mpoelzl commented 5 days ago

Hello! Thanks for the reply. If you could help me to add this as a custom block in an extension that would be fantastic. I have already tried this but couldn't get the block to display correctly when I have a function returning a boolean value as a parameter. It did not display a "pointy" boolean input.

Just to add, this was already discussed here (and you can see the problem) and the feecback was that it is currently not possible to create this in an extension: https://forum.makecode.com/t/create-a-generic-pause-until-block/30448

microbit-carlos commented 5 days ago

@riknoll in order to test this from an extension, would enabling this feature in pxtarget.json have any impact into the MakeCode builds?

riknoll commented 4 days ago

@microbit-carlos not sure what you mean by that. are you talking about code size? if so, that's not an issue. pauseUntil is already available today in TS we just hid the block for it.

@mpoelzl it's true that you can't create a block that takes a predicate like the pauseUntil block, but you can create a higher level block in an extension that calls pauseUntil. for example, if you had some sort of distance sensor:

namespace custom {
    //% block="pause until object detected $distance cm away"
    export function pauseUntilDistance(distance: number) {
        pauseUntil(() => sensor.distance() <= distance)
    }
}
mpoelzl commented 3 days ago

@riknoll Thank you, but the aim really is to have a generic block that takes any predicate.