Forums > MaxMSP

Output of an if statement

July 2, 2007 | 1:23 pm

Hi,
This is probably a very stupid question but I’m stuck.

I’ve got an if statement and I’m trying to output a float.

This is what it would look like in C:

If $i1 < 44
Then output $i1/44 (float)
else output 1.

This is the patch I have so far…

#P window setfont "Sans Serif" 9.;
#P flonum 314 322 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 236 306 27 9109513 / 1.;
#P flonum 271 283 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 234 233 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 206 374 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 278 259 21 9109513 44.;
#P newex 206 345 119 9109513 if $i1 < $i2 then $i3 else 1.;
#P user hslider 340 165 18 128 128 1 0 0;
#P connect 5 0 6 1;
#P connect 5 0 1 1;
#P connect 4 0 1 0;
#P connect 4 0 6 0;
#P connect 4 0 2 0;
#P connect 7 0 1 2;
#P connect 1 0 3 0;
#P connect 0 0 4 0;
#P connect 2 0 5 0;
#P connect 6 0 7 0;
#P window clipboard copycount 8;

As you can see, I can only get an int at the output (1 or 0).

Is there something to specify somewhere for me to get a float?

Thanks for your help.

JC


July 2, 2007 | 1:38 pm

yes, $f1 (float variable) as opposed to $i1 (integer variable).
also be careful of the order of messages, you may need to calculate before you send to the if object…

j

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 206 230 36 196617 t f f b;
#P flonum 334 326 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P newex 219 303 27 196617 / 1.;
#P flonum 270 283 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 206 209 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 206 374 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 270 265 21 196617 44.;
#P newex 206 345 138 196617 if $f1 < $f2 then $f3 else 1.;
#P user hslider 340 165 18 128 128 1 0 0;
#P fasten 5 0 6 1 275 300 241 300;
#P connect 5 0 1 1;
#P connect 8 2 2 0;
#P connect 8 1 6 0;
#P connect 8 0 1 0;
#P connect 4 0 8 0;
#P connect 7 0 1 2;
#P connect 1 0 3 0;
#P fasten 6 0 7 0 224 324 339 324;
#P connect 2 0 5 0;
#P connect 0 0 4 0;
#P window clipboard copycount 9;


July 2, 2007 | 1:41 pm

Quote: amietbeach wrote on Mon, 02 July 2007 14:23
—————————————————-
> If $i1 < 44
> Then output $i1/44 (float)
> else output 1.

Also, when writing values in max objects be aware that "44" refers to an integer with a value of 44, and "44." refers to a float with the same value. A small but important difference, because this will often determine whether your output is float or integer.

j


July 2, 2007 | 1:45 pm

Great!

Cheers Justin!


July 2, 2007 | 1:45 pm


July 2, 2007 | 1:46 pm

On 2 juil. 07, at 15:23, amietbeach wrote:

> Is there something to specify somewhere for me to get a float?

instead of $i1 … $i3, you should use $f1 … $f3

p

_____________________________
Patrick Delges

Centre de Recherches et de Formation Musicales de Wallonie asbl

http://users.skynet.be/crfmw/max


July 2, 2007 | 1:58 pm

a one object solution ;)

#P window setfont "Sans Serif" 9.;
#P flonum 162 253 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 162 159 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 162 200 187 9109513 expr (($f1<44.)*($f1*0.022727))+($f1>=44.);
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P window clipboard copycount 3;

cheers


July 2, 2007 | 2:14 pm

I got the same solution as ej’s left one:

#P window setfont "Sans Serif" 9.;
#P window linecount 1;
#P newex 451 505 27 196617 / 1.;
#P flonum 451 545 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P flonum 451 444 35 9 0 0 0 3 0 0 0 221 221 221 222 222 222 0 0 0;
#P message 601 442 21 196617 44.;
#P newex 451 477 160 196617 if $f1 < $f2 then $f1 else out2 1.;
#P connect 1 0 4 1;
#P connect 1 0 0 1;
#P connect 0 0 4 0;
#P connect 2 0 0 0;
#P connect 0 1 3 0;
#P connect 4 0 3 0;
#P window clipboard copycount 5;

But that one on the right is a beauty!


July 2, 2007 | 2:20 pm

the one object way:

#P window setfont "Sans Serif" 9.;
#P flonum 162 253 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P number 162 159 35 9 0 0 0 139 0 0 0 221 221 221 222 222 222 0 0 0;
#P window linecount 1;
#P newex 162 200 187 9109513 expr (($f1<44.)*($f1*0.022727))+($f1>=44.);
#P connect 1 0 0 0;
#P connect 0 0 2 0;
#P window clipboard copycount 3;

(sorry if it


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