Nested If?

Jason Nerida's icon

How do write a nested if in Max? I want to set values greater than 127 = 127, values less than 0 = 0, and pass them on otherwise. I'm trying this:

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

Seems simple enough but...

Thanks,

J

johnpitcairn's icon

Quote: neridaj@gmail.com wrote on Fri, 13 July 2007 11:48
----------------------------------------------------
> I want to set values greater than 127 = 127,
> values less than 0 = 0, and pass them on otherwise.

Er ... [clip 0 127] ?

Roman Thilenius's icon

i *think* you can do "if ... and if" in [expr], if thats
not true, you could also use 2 if expressions in series.

for the task you have to do i would probably also use
[clip 0 127] yet i trtied to anser the question about "if".

Emmanuel Jourdan's icon

On 13 juil. 07, at 01:48, Jason wrote:

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

> How do write a nested if in Max? I want to set values greater than
> 127 = 127, values less than 0 = 0, and pass them on otherwise. I'm
> trying this:
>
> max v2;
>

If can't do that, the resulting statements are not evaluated so it
won't work. As mentioned by everyone, clip is certainly the most
efficient way of doing that. But you can do it that with some kinda
nested if (in the ? : operand form) in jstrigger. I'm not sure that
I'd be able to read that tomorrow;-)

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

ej

gusanomaxlist's icon
Trond Lossius's icon

In general I will use the "else out2 $f1" approach to do nested ifs (but
in this specific case clip will do the trick, as pointed out already):

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

Best,
Trond

> How do write a nested if in Max? I want to set values greater than 127 = 127, values less than 0 = 0, and pass them on otherwise. I'm trying this:
>
> max v2;
> #N vpatcher 20 74 620 474;
> #P window setfont "Sans Serif" 9.;
> #P window linecount 1;
> #P newex 251 312 246 196617 if $f1 > 127 then 127 else if $f1 < 0 then 0 else $f1;
> #P pop;
>
> Seems simple enough but...

Jason Nerida's icon

That did the trick, thanks everyone.

J