Good patching techniques. Should I use Javascript for more?
Hello, recently I have started using the if object in the place of a select object and a message box like I have been doing since I started with Max. I was just wondering, is there a neater or easier way? I think perhaps I have fallen into a bad habit.
ANYWHO, the point of this was to ask if any of you lovely people can make this without having a ger-zillion(sp?) patch lines and taking longer than it has to:
I am mostly interested in the part which is triggered when the input does NOT equal any of those numbers.
I have tried using the If object with this --
[if ($i1 == 8) || ($i1 == 24) ($i1 == 140) || ($i1 == 156) then 0 else 1]
But that doesn't work. Max hurling abuse at me in the Max window.
Any help is appreciated,
Iyad.
I can't see your patch since I'm on an iPad but it seems to me you could use a [route 8 24 140 156] object and just detect output from the rightmost outlet
there is a typo in it:
[if ($i1 == 8) || ($i1 == 24) ($i1 == 140) || ($i1 == 156) then 0 else 1]
try
[if ($i1 == 8) || ($i1 == 24) || ($i1 == 140) || ($i1 == 156) then 0 else 1]
now it should work.
but if you only need one outlet, you could also use [expr]. this would allow you
to do calculations after the comparison operators, too, which [if] wont allow.
("then (0+$f3) else 5-4")
[expr ($i1 != 8) || ($i1 != 24) || ($i1 != 140) || ($i1 != 156)]
when i am not wrong.
I think the expr would be
[expr ($i1 != 8) && ($i1 != 24) && ($i1 != 140) && ($i1 != 156)]
or
[expr ! (($i1 == 8) || ($i1 == 24) || ($i1 == 140) || ($i1 == 156))]
Thanks for your responses guys. I think I need to get into the expr object more, as it looks super useful.
Is there a way in any of these objects to output different numbers depending on the number that goes in? I can't seem to figure this out using the if or the expr objects.
For example
8 -> 0
24 -> 1
56 -> 2
everything else -> 10
Thanks guys.
If you want each new number you specify to return numbers that increase by 1 each time then the following example using [zl sub] will work.
one thing expr cannot do, is outputting nothing. you will have to use 0 or a placeholder and remove it later with [route 0]
24 -> 1
56 -> 2
is no problem:
expr ( ($i1==24) * 1 ) + ( ($i1==56) * 2 )
0 as output is problematic, as you need the 0 to let false results vanish from the addition.
Thanks guys, I really need to learn more of this stuff, it is pretty awesome. :)
zl sub is definitely the way to go.
However, here's another way to tackle it using vexpr, which is a good skill to know for other problems like this.
Another tip: avoid using multiple objects or additional inlets to solve problems when you can solve it via a list. Spend some quality time with the zl objects and especially vexpr (like expr, but for lists: @scalarmode 1 is magic.) This will save you tons of time, make your code more dependable, and make your code more flexible. In my experience, code works best when you keep patchcords to a minimum.
Learn to look for general problems where you can and solve them well, then store them for use as abstractions. Yes, there is a time for specific solutions, but specific solutions are rarely reusable, and generally don't provide ways of expanding on an idea.