Page 1 of 1

Need help with IF Statements

Posted: Tue Mar 14, 2023 8:27 am
by Puncher
Sorry this might be a newbie question - im coming from a programmer background but im still making rookie steps in maxforlive and struggling with something that is probably easy to solve.

I would like to change the second value of a list item based on a condition and then output that modified list to the next object. the input value to the if-object is the control change from the midiparse object: control change (controller number, value).

I would like to modify the value for a specific controller number.

i tried something like this but it fails:

Code: Select all

if ($i1 == 10) then $i2 = 50. 
and then output $i1 & $i2 as a list.

Re: Need help with IF Statements

Posted: Tue Mar 14, 2023 9:35 am
by [jur]
format it this way:
if $i1==10 then $i2 50

Re: Need help with IF Statements

Posted: Tue Mar 14, 2023 11:25 am
by Puncher
thanks, first problem solved!

can i do

Code: Select all

else if 
in max for live

Re: Need help with IF Statements

Posted: Tue Mar 14, 2023 12:40 pm
by [jur]
Yep.
When in doubt about an object, do a a alt+click on it and it'll open its help window with examples.

Re: Need help with IF Statements

Posted: Wed Mar 15, 2023 8:00 am
by Puncher
thanks for your reply. sorry but i can't get it working

this one seems not correct syntax

Code: Select all

if $f1 > 127 then 127 else if $f1 < 0 then 0 else $f1
it either outputs 127 or the complete code that comes after the first else as plain text

Re: Need help with IF Statements

Posted: Wed Mar 15, 2023 8:51 am
by [jur]
Oh sorry, I didn't understand you...
No you can't have a "else if" like this, just put "else", but I'm not in front of max atm and I always forgot the subtleties of this object so I'm not 100% sure. But as I said, alt+click the [if] object and you'll find your answer in the help patcher.

Re: Need help with IF Statements

Posted: Wed Mar 15, 2023 9:05 am
by Puncher
ok - thanks alot!

Re: Need help with IF Statements

Posted: Wed Mar 15, 2023 5:00 pm
by schlam
hello

[clip 0 127] is your friend here

Re: Need help with IF Statements

Posted: Wed Mar 15, 2023 7:03 pm
by Rivanni
And for simple 'if' statements, you can use the [select] object. For example, [select 127] instead of [if $1 == 127]. The left outlet is the 'then', the right one the 'else'.