If syntax

Jul 8, 2009 at 5:58am

If syntax

Hi all,
I was trying to resolve this problem searching in the forum posts, but i didn’t find anything.
Basically i want to write this sentence in the if object

if (in1+in2) < = in3 then out (in1+in3) else out in2

I’m trying with other alternatives, but its much more complicated in the patch I’m doing.

If anyone can help i would really appreciate it.

Jul 8, 2009 at 6:37am


I don’t think it is possible to do that in a single if object cause of the ($i1+$i3). You’ll probably have to do somthing like that :

– Pasted Max Patch, click to expand. –

if you really want to do that in a single object, you could use expr :

– Pasted Max Patch, click to expand. –

However you can see that the same test is done twice, so that this is not so efficient.

Jul 8, 2009 at 8:57am

The [if] object cannot do mathematical operations, however if would be possible with [expr] as Charles has shown in his post above. The method I would use is in the patch below and takes advantage of the fact that lists sent to most objects, in this case [+], act as though each element was sent to a successive inlet.


– Pasted Max Patch, click to expand. –
Jul 8, 2009 at 3:00pm

hi i am just a beginner with max and even not a very good programmer with max. I wish to use if/else for RFID tags.
But I believe that there might be a problem with the my if then else statement. Can you help me out

Jul 8, 2009 at 5:44pm

Hi Rohit,

In general, you’ll get much more help if you post an example of what it is you are trying to accomplish–like the original poster above. Can you describe what you are trying to do?

Jul 8, 2009 at 6:04pm


Thanks for the answers, but I’m having problems opening the patches, maybe because I’m running max 4.5? I’ve done everything the “post patches to the forum post” says.

Jul 8, 2009 at 6:24pm

Yeah, the gibberish-looking text above is in the new Max version 5 compressed text format that makes posting patches much smaller and easier. Unfortunately, that only works in Max 5.

Jul 8, 2009 at 6:54pm

The patch I posted above looked like this:

[if ($f1+$f2)< =$f3 then $f1 $f3 else $f2 0]
[+ 0.]

With three [flonum] objects going into each inlet of a [pak 0. 0. 0.] before the [if] so that the output is triggered no matter which number box you change. If you have trouble recreating just say and I’ll post a screenshot.


Jul 8, 2009 at 8:29pm

It’s working great!
Thanks a lot, if you are around Buenos Aires i can send you a gift Very Happy
Thanks to all that replied to!

and now, back to work!

Jul 8, 2009 at 8:33pm

Unfortunately not, but never mind, I’m glad it helped. You should definitely have a look at max 5, you can download a 30 day demo for free, it really is a big step up from working with 4.x!


Jul 8, 2009 at 9:04pm

i will!

Thanks again.

Jul 8, 2009 at 10:37pm

I am using RFID tags which give output in form of 013e218c..
something of this sort. I am trying to compare the values using if
like $s==……… then send 0 out2 else 1. something like this but it is giving syntax error. is there a method to type cast in max

Jul 8, 2009 at 10:39pm

Try [zl compare] which can match strings and lists.


Jul 9, 2009 at 9:50am

thanks. I will try it.But can you give me the syntax.


Jul 9, 2009 at 11:31am

Have a look at the [zl compare] helpfile. It has two inlets and you send one list to each, if they are the same it outputs a 1 else a 0. You could then use [sel] or [gate] to trigger or route information depending on what you’re trying to do.



You must be logged in to reply to this topic.