If/Then vs. Logic

Nov 1, 2012 at 5:33pm

If/Then vs. Logic

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!

Nov 1, 2012 at 5:52pm

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. –
Nov 1, 2012 at 6:02pm

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! :)

Nov 1, 2012 at 10:57pm

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

Nov 2, 2012 at 11:22pm

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


You must be logged in to reply to this topic.