Javascript and defineattribute: how to use enumindex?

Roald Baudoux's icon

Hello,

Sadly there's no example with enumindex on the jsthis docs page (https://docs.cycling74.com/apiref/js/jsthis/):

I've tried the following but it triggers a warning in the console : High Consistency: bad number:

var pitchmode = "High Consistency"; 
declareattribute({ name: "pitchmode", embed: 1, style: "enumindex", enumvals: ["High Speed", "High Quality", "High Consistency"] }); 

This modified version gives the same results:

var pitchmode = 2; 
declareattribute({ name: "pitchmode", embed: 1, style: "enumindex", enumvals: ["High Speed", "High Quality", "High Consistency"] });
Noise Wrangler's icon

Try this syntax:

var pitchmode = "High Consistency";   
declareattribute({ name: "pitchmode", embed: 1, style: "enum", enumvals: ["High Speed", "High Quality", "High Consistency"] });

The style value is enum .

Nodanoma's icon

It throws the error, since it's expecting a number as default and enumindex is an invalid 'style'; as mentioned above, use enum instead. See the v8-helpfile under 'attributes', all examples are there. as enumvals you can also declare a dynamic list, it does not have to be hard-coded.