trying to get a bang if two lists are not identical

Hector MacInnes's icon

Hi everyone - quite new to max but I can't seem to find this function (am sure I am being stupid).

I have a patch which is a list of nine numbers, which are all either 0, 1 or 2.

So either 0 0 0 0 0 0 0 0 0, or 1 1 1 1 1 1 1 1 1, or 2 2 2 2 2 2 2 2 2 or 0 1 2 1 1 1 0 2 2 or any combination thereof.

When I hit bang to trigger the number generation, I want to send an onwards bang to one sub-patcher if all the numbers are the same, but a bang to another sub-patcher otherwise.

It's easy enough to get the first bang because I can use the match object and only need three of them. But obviously I can't create further match objects for all the other possibilities.

Select doesn't accept lists, and as far as I can tell zl.sect doesn't perform this because it is checking to see if ANY elements are the same, not if ALL elements are the same. I tried an if object (as in... if $i1==$i2==$i3==$i4 etc. then YES else NO ) but that seemed to be putting out the incorrect answer a lot of the time so I'm assuming that's incorrect grammar or something...?

Any help very much appreciated!

Hector.

Hector MacInnes's icon

that second sentence should read: I have a patch which is *generating* a list of nine numbers, which are all either 0, 1 or 2.

double_UG's icon

zl.compare

Hector MacInnes's icon

so zl.compare allows me to check a generated list against another list, but what I am really trying to do is compare a list internally to see if all it's members are identical or not. Is there a way of doing that directly?

I thought I had made a matrix of 3 zl.compares which would check against the three "identical" options (it is attached to this post) but for some reason it sometimes triggers both the identical and non-identical bangs... it happens when you change from one to the other, even if the values to check against are re-set between checks but I can't figure out why?

bangchooser1.maxpat
Max Patch

double_UG's icon

i don´t know why there is a double trigger, but here is another solution

Max Patch
Copy patch and select New From Clipboard in Max.

Roman Thilenius's icon

to compare list elements one by one you would use [vexpr $i1==$i2]

this can also be a starting point for your original question.

Hector MacInnes's icon

Many thanks both, that's it! Sum the zl.compare results. I couldn't do it with the original list results as there are non-identical lists that sum the same as 1 1 1 1 1 1 1 1 1 but that's now a straight 1 or 0. Will look into the double bang later but back on track now, so thanks again :)

florian1947's icon

You could exploit the fact that with 'all equals', any difference between two consecutive numbers will be zero, whereas else there must be non-zeros.