Javascript and defineattribute: how to use enumindex?
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"] });
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
.
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.
So what is it for?

Which option allows what is possible for regular Max objects: choosing a setting with a number but displaying a text too?

Sorry for the errors in the documentation. We'll fix this up in a future version.
Actually your second way, Roald, is the correct way to do this, and it should work. The key is to use the index for assigning to the variable, not the string value.

Thank you Joshua!
Thank you for clarifying, hadn't seen the property list and that was new to me — makes total sense!