ifelse - does it exist

topic posted Wed, November 10, 2004 - 12:22 AM by  heap
Share/Save/Bookmark
Advertisement
in the "if" patch, is there a way to use an "elseif" statement?

my goal is to generate random number up to 100. then use this as a percentage output for various events. thus,

if x < 10 then 0
else if x >11 && x<30 then 1
else if x>31 && x<50 then 2
else then 3
(etc.)

then I want to feed the result to a select and have that go to each of my possible outcomes.

is this possible? I can't get a "elseif" or "else if" statement to work, it seems that the "if" object only supports one "if" and one "else."

response appriated.
posted by:
heap
New York City
Advertisement
Advertisement
  • Re: ifelse - does it exist

    Sun, November 14, 2004 - 8:49 PM
    if binary ops work the same in max as pd (send 0 or 1), then you can just a bunch of [select 1]'s together w/ the bin ops to get this effect (the && would be rendered as short circuting the first conditional at the second outlet of select to the bin op in the next "else if")

    [x < 0]
    |
    [select 1]
    | .........|
    [0].......|
    |............\
    [outlet]..[x > 11]
    .............|
    .............[select 1]
    .............|..............\
    .............[x < 30].....[bang]
    .............|.................|
    .............[select 1]...|
    .............|..............\..|
    .............[1].............[bang]
    .............|.................|
    .............{outlet].......[x > 31]
    ...............................|
    ...............................[select 1]
    etc, etc.

    haven't tested this, but something like it should work for what you are trying to do.

    route would also work, but you would have to know in advance all of the possible values of x. 100 element [route] would be a line drawing nightmare...
    • Re: ifelse - does it exist

      Sun, November 14, 2004 - 8:52 PM
      d'oh. disregard the second outlet on the 3rd [select]
      • Re: ifelse - does it exist

        Sun, November 14, 2004 - 10:05 PM
        d'oh x 2 - disregard that disregard.

        you can also create some lists with [pack] that contain x/min/max and send them to the [split] object, it seems. the first solution is general to bin ops. this one specific to selecting values in ranges.

Recent topics in "Max/MSP/jitter"