Need help with IF Statements

Learn about building and using Max for Live devices.
Post Reply
Puncher
Posts: 7
Joined: Sun Mar 21, 2010 3:15 pm

Need help with IF Statements

Post by Puncher » Tue Mar 14, 2023 8:27 am

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.

[jur]
Site Admin
Posts: 5311
Joined: Mon Jun 01, 2015 3:04 pm
Location: Ableton

Re: Need help with IF Statements

Post by [jur] » Tue Mar 14, 2023 9:35 am

format it this way:
if $i1==10 then $i2 50
Ableton Forum Moderator

Puncher
Posts: 7
Joined: Sun Mar 21, 2010 3:15 pm

Re: Need help with IF Statements

Post by Puncher » Tue Mar 14, 2023 11:25 am

thanks, first problem solved!

can i do

Code: Select all

else if 
in max for live

[jur]
Site Admin
Posts: 5311
Joined: Mon Jun 01, 2015 3:04 pm
Location: Ableton

Re: Need help with IF Statements

Post by [jur] » Tue Mar 14, 2023 12:40 pm

Yep.
When in doubt about an object, do a a alt+click on it and it'll open its help window with examples.
Ableton Forum Moderator

Puncher
Posts: 7
Joined: Sun Mar 21, 2010 3:15 pm

Re: Need help with IF Statements

Post by Puncher » Wed Mar 15, 2023 8:00 am

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

[jur]
Site Admin
Posts: 5311
Joined: Mon Jun 01, 2015 3:04 pm
Location: Ableton

Re: Need help with IF Statements

Post by [jur] » Wed Mar 15, 2023 8:51 am

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.
Ableton Forum Moderator

Puncher
Posts: 7
Joined: Sun Mar 21, 2010 3:15 pm

Re: Need help with IF Statements

Post by Puncher » Wed Mar 15, 2023 9:05 am

ok - thanks alot!

schlam
Posts: 144
Joined: Mon Dec 14, 2020 11:51 am

Re: Need help with IF Statements

Post by schlam » Wed Mar 15, 2023 5:00 pm

hello

[clip 0 127] is your friend here

Rivanni
Posts: 409
Joined: Sat Nov 26, 2016 12:30 pm

Re: Need help with IF Statements

Post by Rivanni » Wed Mar 15, 2023 7:03 pm

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'.

Post Reply