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: https://github.com/microsoft/pxt-ev3/issues

control.programName() is available at https://makecode.mindstorms.com/beta

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
ELSE
  flash bottom of screen
ENDIF

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?