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.

Roald Baudoux's icon

So what is it for?

Roald Baudoux's icon

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

Joshua Kit Clayton's icon

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.

Roald Baudoux's icon

Thank you Joshua!

Nodanoma's icon

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