Microsoft MakeCode

How can I access the name of my program?

I want to display the name of my program on the screen. I have the version number in the name and change it every time I download code. I couldn’t find any variable to access the name. Is there one?

1 Like

I don’t think we have an API for that, unfortunately. Feel free to file a feature request here:

control.programName() is available at

1 Like

Awesome! Do you know when this feature will be available outside of beta?

Is there any way to access the device type or its capabilities from a MakeCode program? I’d like to be able to write code which uses NeoPixels on PyGamer if it runs on a PyGamer and uses the vibration motor on Kitronik ARCADE if it runs on one of those. I’d like to do that in Blocks.

Some sample code showing the recommended way to do this would be really useful.

I believe these APIs are no-ops (or should be, if not file a bug) when the feature is absent. So you can just use the feature (vibration, neopixels, whatever) and it will be just ignored if the hardware doesn’t have it.

It’s a bad idea to detect a specific board, since there are new boards being added. Feature detection would be more useful I guess.

The no-op approach prohibits alternate behaviour based on features, e.g.

IF got-five-neopixels THEN
  flash neopixels
  flash bottom of screen

And there’s the question of what do input based ones do, e.g. light sensor.

I agree that board detection is a niche case but there’s no reason to prohibit it. This is useful for code which tests hardware with user interaction to ensure it’s healthy. For classroom use you sometimes want to be able to put something on the board for students/teachers to quickly make sure everything is functioning and working normally.

BTW, on a slightly different subject, I’ve not tried putting the wrong target .uf2 file on a device. What’s supposed to happen there?

There is control.getConfigValue API that you can use to probe the board the same way the runtime does. You can drop current.uf2 from your board on to see actual config of your board. You should be able to use control.getConfigValue(DAL.CFG_BOOATLOADER_BOARD_ID, 0), however some manufacturers just clone an existing config and you end up with multiple boards with the same ID. However you can query other things, for example control.getConfigValue(DAL.CFG_NUM_NEOPIXELS, 0). Feel free to wrap this up in an extension!

If you drop wrong UF2 it will be ignored, due to family-ID feature, see

1 Like