Forums > MaxMSP

if, then, else, how about AND?

February 19, 2008 | 7:58 am

I’ve bumped into this problem a few times, and the limitations of the expr object seriously can annoy when i need an AND statement ment in there.

does anyone know an easy way of achieving this?

Thanks for any help.


February 19, 2008 | 8:24 am


February 19, 2008 | 9:14 am

yeah thats right. does that work? because if it does it isn’t in my manual!

thanks for the reply.


February 19, 2008 | 10:32 am

I searched for this functionality before, didn’t know [if] could do it. Thanks!

We need more examples…


February 19, 2008 | 12:04 pm


February 19, 2008 | 2:50 pm

This seems to have worked for my needs…

Using the if/then/else object…

if (($f1 > $f2) &&( $f1 > $f3)) then send Test bang

Hope that helps…

I was hoping to do nested if/then/else statements, but instead had to split them up over a few objects instead.


February 20, 2008 | 5:05 pm

Max uses C-syntax throughout expr and if and sprintf and a bunch of other places. C-syntax is ‘&&’. ‘AND’ is sort of COBOL or SQL or Pascal. And what’s the object called that does ‘logical and’?

It might be helpful if the documentation made this explicit in every single place, but in the meantime it’s something to look out for and get used to. It’s also been discussed on the list dozens of times. At least now you know;-



kjg
February 21, 2008 | 12:41 am

Quote: Peter Castine wrote on Wed, 20 February 2008 18:05
—————————————————-
And what’s the object called that does ‘logical and’?

logical and [&&]
bitwise and [&]

|| am i not understanding you Peter? :)

regards,
kjg


February 21, 2008 | 1:53 pm

One should never answer rhetorical questions.


February 21, 2008 | 9:55 pm

is it possible to use sprintf or expr or something else to compare if two symbols are equal and then produce an output?


February 21, 2008 | 10:02 pm

What are the symbols…?

Strings, numbers?

If numbers, you can use == comparison operator

For string, you could try jasch strcmp external…

http://jasch.ch/dl/default.htm


February 21, 2008 | 10:21 pm

[select] ?

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P hidden newex 98 329 88 196617 bgcolor 90 90 90;
#N vpatcher 44 104 686 530;
#P window setfont "Sans Serif" 9.;
#P newex 365 115 48 196617 loadbang;
#P window linecount 1;
#P message 370 170 92 196617 frgb 255 255 255;
#P message 389 186 93 196617 brgb 255 255 255;
#P newex 184 58 40 196617 t 1 b b;
#P window linecount 0;
#P newex 117 55 40 196617 t 0 b b;
#P inlet 184 30 15 0;
#P inlet 116 29 15 0;
#P outlet 117 230 15 0;
#P message 232 115 68 196617 frgb 255 0 0;
#P window linecount 1;
#P message 161 136 81 196617 brgb 255 255 0;
#P message 262 134 57 196617 brgb 0 0 0;
#P window linecount 0;
#P message 145 118 56 196617 frgb 0 0 0;
#P connect 5 0 7 0;
#P connect 9 0 4 0;
#P connect 10 0 4 0;
#P connect 3 0 4 0;
#P connect 1 0 4 0;
#P connect 8 0 4 0;
#P connect 7 0 4 0;
#P connect 2 0 4 0;
#P connect 0 0 4 0;
#P connect 7 1 0 0;
#P connect 7 2 2 0;
#P connect 6 0 8 0;
#P connect 8 1 3 0;
#P connect 8 2 1 0;
#P connect 11 0 10 0;
#P connect 11 0 9 0;
#P pop;
#P newobj 114 187 49 196617 p (^_^);
#P window setfont "Sans Serif" 36.;
#P user ubumenu 114 235 47 196644 0 0 1 0;
#X setrgb 0 0 0 255 255 0 234 234 234 4 4 4 141 141 141 112 112 112;
#X add :);
#X add :(;
#X prefix_set 0 0 0;
#P window setfont "Sans Serif" 9.;
#P message 146 74 41 196617 mccain;
#P message 90 73 38 196617 obama;
#P button 153 150 15 0;
#P button 114 150 15 0;
#P newex 114 115 88 196617 sel obama mccain;
#P connect 4 0 0 0;
#P connect 3 0 0 0;
#P connect 0 0 1 0;
#P connect 1 0 6 0;
#P connect 6 0 5 0;
#P connect 0 1 2 0;
#P connect 2 0 6 1;
#P window clipboard copycount 8;

Quote: blairell wrote on Thu, 21 February 2008 22:55
—————————————————-
> is it possible to use sprintf or expr or something else to compare if two symbols are equal and then produce an output?
—————————————————-


February 21, 2008 | 10:39 pm

and of course [match] and [route] :
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 406 157 52 196617 walkiries;
#P message 360 157 44 196617 wikings;
#P button 416 228 15 0;
#P button 363 228 15 0;
#P newex 363 187 116 196617 route wikings walkiries;
#P newex 184 108 75 196617 sprintf set %s;
#P message 234 72 48 196617 dandruff;
#P message 184 72 48 196617 shampoo;
#P button 66 188 15 0;
#P message 117 103 48 196617 dandruff;
#P message 117 213 50 196617 dude;
#P message 66 103 48 196617 shampoo;
#P newex 117 183 62 196617 prepend set;
#P newex 117 149 37 196617 match;
#P connect 0 0 5 0;
#P connect 0 0 1 0;
#P connect 13 0 9 0;
#P connect 12 0 9 0;
#P connect 9 1 11 0;
#P connect 9 0 10 0;
#P connect 1 0 3 0;
#P connect 7 0 8 0;
#P connect 6 0 8 0;
#P connect 8 0 0 0;
#P connect 4 0 0 0;
#P connect 2 0 0 0;
#P window clipboard copycount 14;


February 21, 2008 | 10:55 pm

the first example doesn’t compare if two strings are equal, it just sets an output based on if an input equals a predefined result.

the shampoo/dandruf example is close, but a bit dangerous because it doesn’t have split inputs, so if a string get sent from the same source twice it will return true when it probably shouldn’t. but with a bith of fiddling it will work! thanks


February 21, 2008 | 11:20 pm

o ok i see
an other solution would be to convert characters into into integers using [atoi] and compare the resulting list of numbers.
[L==] from Peter Elsea’s set is handy for that.
[vexpr] does logical operations as well

#P button 98 260 15 0;
#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P message 98 111 53 196617 toothache;
#P message 83 94 50 196617 headache;
#P newex 98 139 40 196617 atoi;
#P message 158 112 50 196617 headache;
#P newex 158 139 40 196617 atoi;
#P message 308 138 51 196617 weetabix;
#P toggle 383 264 15 0;
#P message 340 155 59 196617 ovomaltine;
#P newex 340 182 40 196617 atoi;
#P newex 383 212 27 196617 L==;
#P message 400 155 59 196617 ovomaltine;
#P newex 400 182 40 196617 atoi;
#P toggle 98 226 20 0;
#P newex 158 169 27 196617 t b l;
#P newex 98 198 87 196617 vexpr $i1==$i2;
#P connect 2 0 15 0;
#P connect 12 0 0 0;
#P connect 10 0 1 0;
#P connect 11 0 10 0;
#P connect 14 0 12 0;
#P connect 13 0 12 0;
#P connect 7 0 6 0;
#P connect 9 0 6 0;
#P connect 6 0 5 0;
#P connect 5 0 8 0;
#P connect 4 0 3 0;
#P connect 3 0 5 1;
#P connect 0 0 2 0;
#P connect 1 0 0 0;
#P connect 1 1 0 1;
#P window clipboard copycount 16;

Quote: blairell wrote on Thu, 21 February 2008 23:55
—————————————————-
> the first example doesn’t compare if two strings are equal, it just sets an output based on if an input equals a predefined result.
>
> the shampoo/dandruf example is close, but a bit dangerous because it doesn’t have split inputs, so if a string get sent from the same source twice it will return true when it probably shouldn’t. but with a bith of fiddling it will work! thanks
—————————————————-


February 22, 2008 | 4:35 am

ahh nice idea. ill give that a shot!


Viewing 16 posts - 1 through 16 (of 16 total)