Forums > MaxMSP

If/Then vs. Logic

November 1, 2012 | 5:33 pm

Hello everyone,

From what I understand, "if" and "expr", while easier to comprehend for a novice programmer, are an inefficient way to check and compare values. However, most of Max’s logic objects are limited to only comparing two numbers.

For example, I have the following statement, "if $i1 + $i2 + $i3 + $i4 + $i5 + $i6 + $i7 + $i8 + $i9 == 0 then bang". All I really want to do is check 9 toggles, bang if they’re all off. It seems like I should be able to use && for something like this, but it will only compare two numbers. I even thought about using coll or some sort of list operation, but that seems like it would be unnecessarily complicated.

Anyone know the best (most efficient) way to perform operations like this?

Thanks in advance for your help!

November 1, 2012 | 5:52 pm

In this particular situation another logic is possible, putting the values of all the toggles in a list and summing the result. If you have 9 times a 1 (toggle on) than the sum is 9. This you can feed to a selecting procedure…

– Pasted Max Patch, click to expand. –

November 1, 2012 | 6:02 pm

Rock and roll! I had a feeling that some sort of list would be the way to go. I was actually checking to see if the toggles were all off, so changing sel 9 to sel 0 returns the bang I’m looking for.

Cheers! :)

November 1, 2012 | 10:57 pm

You might also want to look into [vexpr], the list-savvy version of [expr].

November 2, 2012 | 11:22 pm

to find out if the sum of al is zero, multiplying them using [accum] should be enough.

Viewing 5 posts - 1 through 5 (of 5 total)