I want to create a function block which has a drop-down parameter as well as normal number entry parameters. For example: - (this screenshot is from an approved “servos” extension).
I can’t figure out what is needed in the TypeScript.
I got it working (lots of trial and error!). Here is a sample JS code snippet:
enum alarmNum {
A1,
A2
}
//NB this is OUTSIDE the namespace!!!
//% weight=20 color=#b77ff0 icon="\uf017" block="DS3231"
namespace DS3231 {
/**
* set alarm
* @param name is the Alarm name
* @param minute is the Minute that will be set, eg: 13
* @param second is the Second that will be set, eg: 0
*/
//% blockId="DS3231_SET_ALARM" block="set alarm %name| minute %minute|second %second"
//% weight=60 blockGap
//% parts=DS3231 trackArgs=0
export function setAlarm(name: alarmNum, minute: number, second: number): void {
}
}
The key things:
- The drop-down list is created in an enum (mine is called “alarmNum”) which is outside the namespace. That’s important!
- The list is given a name (I used “name”) and is defined in the function’s parameter list as being of type {enum-name} - so: export function setAlarm(name: alarmNum,
I did struggle with the documentation …
1 Like
A screenshot of the above example:
Nice!
For what it’s worth, the “playground” is a great resource for seeing a lot of the block alternatives and rapid prototyping: https://makecode.com/playground (That’s a tip I picked up from this forum)
1 Like