Forums > MaxMSP

preventing duplicates in umenu

February 1, 2012 | 2:42 pm

I have a umenu that is populated by javascript. However, sometimes the output of the javascript is already in the umenu. In this case I need to prevent the duplicate from being added. How may I do this?

Thanks much in advance


February 1, 2012 | 5:33 pm

I usually just send a ‘clear’ message to the umenu first

February 1, 2012 | 7:56 pm

I mean, for append messages. I don’t rebuild the menu, I just add stuff to it.

February 1, 2012 | 8:13 pm

You didn’t mention a coll!

I don’t know offhand whether the umenu has an attribute to prevent duplicates but in general it’s not a good idea to use a view as the model as well.

Keep your collection of data stored somewhere else (in a model) and handle (prevent) duplicates there.

Then whenever there’s a change, your model will update umenu. The easy way to do that if you don’t want your model to keep track of what it has previously sent, is to clear the umenu and resend everything.

February 3, 2012 | 7:45 am

there is a patch that does this in the st.ools collection called St.oleMenu

But I would second the advice about keeping the list elsewhere–esp as you can’t get umenu to dump its contents afaik. I’m pretty sure St.oleMenu does this itself.

February 3, 2012 | 8:26 am

If you’re doing this in javascript you should be able to check the [umenu] objects "items" attribute and use an if statement to make sure that the string you want to add isn’t already present.

Let me know if you’d like an example patch for this.

February 3, 2012 | 12:12 pm

here’s a way to not append if it’s already in there, but i used objects, not js, so i don’t know if this can help you.

— Pasted Max Patch, click to expand. —
Viewing 7 posts - 1 through 7 (of 7 total)

Forums > MaxMSP