Help with conditional expressions
  • Conditional expressions can be very powerful, in theory. But all the expression node's Help menu says about conditional syntax is "x?a:b -- conditional. b if x is 0, otherwise a". To me, this implies that the only condition this node can handle is "0 vs. other". I'm not smart enough to transform all the multifaceted conditions I want to use into either 0 or other.

    So, my question: Can the expression node handle other types of conditions? If so, what is the syntax for those? For instance, "If x > y, then a, otherwise b". And what about combining conditions? For instance, "If x > y AND x < z, then a, otherwise b". And what about "either/or" conditions? Is there some way to do those? In a nutshell, what is the syntax for conditions other than "0 vs. other"?

    If the expression node really can handle more complex conditions than "0 vs. other", it'd be great to see this reflected in the Help menu's documentation in a future update.
  • (x > y) evaluates to 1 if true and 0 if false
    Same with the other comparison operators ==, != etc.

    This is useful for switching for instance, if you use an expression for the control input on a crossfader node ... there you've got a functional A/B switch.

    You can also do that directly in the expression node with something like:

    (Switch > 0):A?B
  • I answered this on the other thread, but here's the copy/pasted answer:

    If you want to string multiple conditionals together, you multiply them (Conditional 1)*(Conditional 2) = True only when 1+2 are true.

    If you want an expression for when either is true, use addition (Conditional 1)+(Conditional 2) = True when either 1 or 2 is true.

    You can mix these together as well, so (C1)*(C2)+(C3) = True when both C1 and C2 are true and/or when C3 is true.

    You may need to clamp the output of the expression to keep it between 0 and 1 for some applications, so: clamp((C1)*(C2)+(C3),0,1)

    As for your specifics, see attached image (forum can't handle carrots correctly I guess)

    I think stringing them together like this is easier to understand and is more explicit than the conditional expression, which I never use.

    image
    Screen Shot 2017-08-02 at 12.14.59 PM.png
    381 x 197 - 22K
  • Thanks fellas. I'll take these responses and see what I can do with 'em!
  • No problem! Let me know if you need any more help too! What are you building with these?
  • Well I've had this question about conditionals for a while now, but the specific thing that caused me to finally post about it is a counter module I'm working on, similar to the counter module that you created.

    Basically, using the S&H node, I wanted something that would start with a number I fed into it (a), then increase that number by any increment I specify (b) up until a maximum value that I would also specify (c), and then return to 0 once that c was surpassed to begin the count again. The function of the conditional in this module will be to reset the counter back to 0 only once x > c (where x is the signal coming out of the S&H node).

    So while x <= c, the conditional adds b to x each time there's a trigger, then once x > c, the conditional feeds a 0 back into the S&H node to restart the count.
  • Here ya go! Instructions are inside.
    Count By X.audulus
    10K
    Count By X Demo.audulus
    55K