Microsoft MakeCode

Extension that modifies the simulator

Hello,
I was wondering if it is possible to write an extension that modifies the simulator? I use some extensions that allow students to program different sensors and I would like them to be able to test their programs by choosing different sensor values in the simulator (like the light sensor on the micro:bit) before they load the program on to the micro:bit. This is especially important since school is going to most likely be virtual this fall.
Thanks!
Alex

Hi Alex,

I’ve been investigating this concept for a while. Someone else may have a better answer, but I was considering using the “Experimental” Editor Extensions feature, which would require explicit effort for users to opt-in to using, and it would not be as visible as the built-in interactions, like the light sensor.

My basic idea is to allow users to enter a table of times and periods to simulate the sensor in the extension frame. For example, they may indicate the sensor shows 20 for 2 seconds, then 22 for 4 seconds, then 26 for 12 seconds, then 22 for 2 seconds. A total of 20 seconds of values are entered and they’d repeat every 20 seconds. Of course, if you’re just setting a specific value rather than a “schedule”, you could do so with a GUI instead.

Details about these types of extensions are here: https://makecode.com/extensions/extensions
and there’s an example extension here: https://github.com/samelhusseini/pxt-editor-extension-sample

I hope someone else can share a better approach!

For security reasons, it is not currently possible to inject any javascript into the simulator. In a nutshel, it’s not trivial right now.

Here are a few ways I can think of making this work:

  • fork github.com/microsoft/pxt-microbit and implement additional behaviors in the pxt simulator itself. This is potentially complicated as our codebase is rather large. Send us the pull request! :slight_smile:
  • embed MakeCode as a widget in your page and communicate to the simulator via iframe messages. You will receive messages for serial, radio packets.

Just to check…PRs to update simulation behavior for specific extensions may be accepted? (That would be great!)