declareattribute() and an array
i have a variable named defaultRows. it is then declared an attribute.
if i enter a list of numbers in the js inspector, i can iterate through the list as if it were an array,
but max periodically throws a fit and says defaultRows has no properties.
what is the best way to get an array of numbers from the user and into an attribute?
> what is the best way to get an array of numbers from the user and into an attribute?
If you have an attribute, you should be able to send your js object the message "defaultRows 1 2 3 4". I feel like I'm missing something here though...
yes, that works, but i guess i should have been clear that i wanted to avoid another object just for that. basically, is there something special i need to do to allow the user to just type it into the inspector.
Wait, by users do you mean someone who's building a patch using your js object, not someone using said patch? If that's the case, check out the jsarguments property of your this object. The standard max way of setting a default variable for an attribute would be to provide arguments of the form "@defaultRows 1 2 3 4" to the object. Unfortunately, the js object doesn't implement that functionality for you automatically. As far as I know, you'll have to parse the arguments yourself.
Also, I'm going to guess that Max is complaining about defaultRows having no properties because you're not giving it a default value, which is probably good to have in any case. That way you're guaranteed that it will have some sane value at all times.
ok (thank you, by the way, for these responses. :-))
i have made one js object using jsarguments. i understand those...very straightforward and good when i only had a couple arguments. but array i want can be up to 15 numbers, and i think that will be silly looking and would not work so well. if i have other arguments to get. (mostly aesthetics...so i CAN let it go.)
so what i would like is to tell people to open up the inspector. the reason i am asking here is that the attribute has a tendency to erase itself and i don't know why.
i actually have my functions checking for sane values when it comes time to use defaultRows. if there are none, it will do nothing with them.
in some ways, the "max way" of dealing with attributes (in fact, one of the points of attributes) is that you don't make this decision for downstream developers. your object has some property, and that property can be altered by message, in the object arguments, or by setting it in the object inspector. You can't (and don't have to) predict what each developer is going to need or want. By making it an attribute, you automatically get the first and third options implemented for you. I think it's reasonable to expect that a Max user knows how to set an attribute; there's no need to explicitly push them to the inspector. If you really want to, maybe a note in your documentation would be good.
also, apparently your checks for sane values aren't sufficient if max is complaining that the object has no properties. as for it getting erased... well, that will happen every time your object is reinstantiated, which will happen, among other times, whenever you change the javascript source (automatically in the internal editor, only with an external editor if you've set autowatch=1).
by giving it a default sane value of [] (the empty array), you can probably eliminate a lot of explicit error checking; for example, loops will simply degrade to noops. If the value is unset however, you will get the error you described when checking against defaultRows.length.
fair enough. thank you for the insights