I wanted to use an interval based execution instead of relying on the forever loop with sleeps. Since I didn’t find a good solution so far from the pxt side of stuff, I looked at the actual uBit and mBed code, and it seems they have a Ticker that allows you to add an interval based execution. However, I wanted to use this from the Blocks interface and started with a pxt extension. However, I am a little bit confused about the way this would have to interact, as I woudl not attach to the message bus, and I would be using mbed directly without using the microbit-dal.
Wait for Event, but this seems to run a piece of code in parallel with a pause statement, and the caller would also have to be a parallel, like a while(1) loop to accomplish having a callback being triggered after the event ‘raised’.
I would hope something more low-level with a timer interrupt from hardware is possible.
Also, I know arcade has the following:
game.onUpdateInterval(1000, function () {
})
which as far as I remember uses the frame loop to determine if a certain time period has passed before invoking the call… but this is not available on a micro:bit (or maker?)
it is not the precision I am looking for, but the use and integration options between lower level code and extensions. For now I’ll try to go the route of using the aforementioned option. However, am I even allowed to use the control namespace within an extensions, and if so… how? Somehow the layering is not clear to me yet and would like to know what is available to me. I am looking at https://makecode.microbit.org/reference and only basic, serial, pins, etc are available to me.
Correction: control IS available, but inBackground is exposed instead of runInParallel, and onEvent.
As I figured as it all referred to game logic (I had seen these functions before, just unsure if they were able to be used… and therefore the extension).
We decided to rename it in our shared library (pxt-common-packages) because we thought the wording was more readable. micro:bit is our oldest editor and it still uses the old name because that’s what it originally shipped with; I think we planned to update it at some point but ultimately didn’t think it was worth upgrading existing scripts/documentation.