Comparing two numbers?

Mar 17, 2009 at 8:23pm

Comparing two numbers?

I am trying to make a patch that will determine whether two frequencies are equal or not. My current patch is below, but what I’m trying to do at the moment is get a green light if they ARE equal, and a red light if they’re not.. but currently I’m getting a red light when they are equal, and the green light’s doing nothing. It’s quite likely my if object which at the moment is “if $i1==$i2 then bang else out2 bang” but I’ve tried a few various methods, and looked through the help files and nothing seems too obvious!

Very grateful for any help!

– Pasted Max Patch, click to expand. –
#42901
Mar 17, 2009 at 8:36pm

I can’t test your patch because I don’t have max 5 but it’s pretty simple to do.

Here are two simple ways.

#P window setfont “Sans Serif” 9.;
#P user ubumenu 249 228 100 196617 0 1 1 0;
#X add red light;
#X add green light;
#X prefix_set 0 0 0;
#P user ubumenu 67 228 100 196617 0 1 1 0;
#X add red light;
#X add green light;
#X prefix_set 0 0
0;
#P window linecount 1;
#P newex 249 169 131 196617 if $f1 == $f2 then 1 else 0;
#P newex 67 144 131 196617 bondo;
#P flonum 188 116 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 67 116 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 67 169 131 196617 == 0.;
#P connect 4 0 6 0;
#P connect 0 0 5 0;
#P connect 3 0 0 0;
#P fasten 3 0 4 0 72 165 254 165;
#P connect 3 1 0 1;
#P fasten 3 1 4 1 193 165 375 165;
#P connect 2 0 3 1;
#P connect 1 0 3 0;
#P window clipboard copycount 7;

#153598
Mar 17, 2009 at 8:37pm

You need to remove “out1″ from your [if] object. If you open the Max window, you will see that you are getting an error message with your current configuration.

– Pasted Max Patch, click to expand. –
#153599
Mar 17, 2009 at 8:44pm

BTW, here’s a way to do it without using an [if] object AND so that it evaluates even if only one number changes.

– Pasted Max Patch, click to expand. –
#153600
Mar 17, 2009 at 8:50pm

Thank you, that was all really helpful!

I had started off without the out1, but when it didn’t work I added it – no error though, but it clearly wasn’t working!

I’ve now managed to get everything working the way it should though, thank you for your help Smile

#153601

You must be logged in to reply to this topic.