How do you predefine an Enum/dropdown?

How do you predefine an Enum/dropdown parameter in a custom block? If it’s even possible.

For the people who don’t know what I’m talking about here is an example:
image
Screenshot 2024-01-13 115930

All help is appreciated :slight_smile:.

2 Likes

@ARandomGuyOnMakeCode you can do it two ways:

  1. the default is the first item in the enum, so you can just move it
    in the enum to the first spot
  2. you can use param.defl="MyEnum.Value". here’s an example:
enum MyEnum {
    //% block="one"
    One,
    //% block="two"
    Two
}

/**
 * Custom blocks
 */
//% weight=100 color=#0fbc11 icon=""
namespace custom {
    //% blockId=my_custom_block_id
    //% block="here's an enum $value"
    //% value.defl=MyEnum.Two
    export function foo(value: MyEnum): void {
    }
}
5 Likes

Thank you for the information. Much appreciated :slight_smile:.