if-then-else expression in [expr] and [codebox]?

    Feb 12 2012 | 12:43 pm
    Hi all-
    I know there are other solutions, but is there an if-then-else or equivalent in Gen's [expr] and [codebox]?
    I seem to remember a statement that there was, but now can't find any documentation.
    Best wishes, Charles

    • Feb 12 2012 | 2:03 pm
      have a look here, the same applies to expr inside gen: https://cycling74.com/forums/better-option-for-posterization
      about codebox, i haven't tried yet but i understood it takes C code so i guess if/then/else statements should work: https://cycling74.com/tutorials/week-47-waveshaping-with-gen/
    • Feb 12 2012 | 3:48 pm
      no, codebox doesn't take if, then, else, for, etc. but apparently it will one day.
      codebox is not C. it just feels a little like it. but it is very very simple and easier than javascript or lua.
      in gen and codebox i assign first and use [switch]: x = w ? y : z; or [selector] or [gate] (same as max land).
    • Feb 12 2012 | 3:52 pm
      tanx for pointing that out!
    • Feb 12 2012 | 4:38 pm
      @pid, @dtr-
      Thanks for pointing all this out.
      Best, C.
    • Feb 14 2012 | 1:27 am
      Hello I was sitting with a similar problem the last days, missing if-else, it looks like there is an example of how to get around it,using ? operator within codebox,, needing extra lines of code, intermittent variables its about pd filters realized in gen https://cycling74.com/forums/max-analogs-for-pds-bp-and-hip a bit down the page, porting c code to gen, >>stkr<< writes himself : (looks ridiculous - getting around GenExpr limitations)
      greetings vilbjørg
    • Feb 14 2012 | 12:21 pm
      Well, [gen~] is a synchronous language. Just because it has a C-like syntax...
      Someone could prove me wrong, but I think it has to do with preserving state across time spent in the rendering loop. Currently with [gen~] everything is forgotten when the audio interrupt is exited. There are exceptions at the object level, like [sah].
      But if conditionals have got your nose twisted, try anything that changes the flow of time, like a "for" or "while" loop!
      Best, Charles
    • Feb 14 2012 | 3:31 pm
      Hi greetings and just IF more people follow this if-else ? discussion THEN this tiny simple example is working, its doing C*sin(x) where C is variable parameter and x is fed back in the loop and trig is a running sample counter input, so that there will only be a new output every so many samples.
      x = in1; c = in2; trig = in3; xout = (trig == 1) ? c * (sin (x)) : x; out1 = xout;
      here on my babysocks in the code landscapes i hope that in this way there is some some cpu saving in the sense that the csinx calculation is only done IF trig==1.. for more complex algorithms this would matter i bet. greetings v