Profile image

Funky Trees Addendum - OR logic operator behavior

67.1k SnoWFLakE0s  3.6 years ago

While I was trying to bug fix some FT code with no avail, I turned to man himself--WNP78--and got some useful information that I felt you all might like to know.

Here's what he says about OR operator behavior:

If the first argument of an OR is true, it will just return true without checking the second argument

This implies that frame-update functions like that of sum, smooth, rate (i.e. time based functions) will NOT update if it is part of the second argument, leading to inconsistencies if you're trying to use the "same function" compared across multiple OR operators.

For example, in the code sum(Time) > 1 | sum(2*Time) > 1, while sum(Time) > 1, sum(2*Time) will not update (not change). Keep this in mind while designing functions. If you need to use OR in conjunction, try to use boolean algebra instead, that is, try to figure a numerical comparison method instead of logic-based.

Hope this helps any stumped coders!

  • Log in to leave a comment
  • Profile image
    Dev WNP78

    This is the same for and, ie if the first expression comes out as false, it knows the result will be false so doesn't waste time checking the second operand. The only other place similar behaviour place is observed is in the ternary operator - only the selected expression will be evaluated.

    Pinned 3.6 years ago
  • Profile image
    13.9k ChrisPy

    ok this makes sense now. I was trying to use smooth on something and it didnt work for a while

    3.6 years ago
  • Profile image
    23.4k marcox43

    really useful info, this explains why my automated airbrakes didn't get overrid by manual control because the manual control was on the second bracket...

    3.6 years ago
  • Profile image

    @SnoWFLakE0s it was like (blah blah 1200 character funky tree code that works) * clamp(-Activate7, 0.5, 1) and it ignored the clamp(-Activate7, 0.5, 1) at the end and it just did the (blah blah 1200 character funky tree code that works) bit like the last bit wasn't there

    3.6 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @AN2Felllla
    .
    Check your brackets. FT tries to auto-complete if possible, sounds like that might be the case. Are you using implicit multiplication as well?

    +1 3.6 years ago
  • Profile image

    2 days ago I had an issue where I was trying to make a long equation activate at half with activate 7 on and operate at full with activate 7 off. (clamp(-Activate7, 0.5, 1)). For some reason, putting this at the end of the equation (which was surrounded in brackets) had no effect on the equation, but putting it at the start made it work fine, despite the only difference being the location...

    +1 3.6 years ago
  • Profile image

    le thinking cap has arrived

    +1 3.6 years ago
  • Profile image
    162k spefyjerbf

    Thank you for the flashbacks to my weedout CS class where we had to deal with this sort of stuff using C.

    3.6 years ago
  • Profile image

    r/Simple Planes
    Reddit/Simple Planes
    Lets do that
    So we can help pep
    That are having trouble of
    Coding
    My answer: yes

    3.6 years ago
  • Profile image
    59.7k PapaKernels

    I have no idea what that means but ok!

    3.6 years ago
  • Profile image
    9,103 ZWLenning

    I long to be at a level in funky trees where this would be a problem I would come across

    3.6 years ago
  • Profile image
    6,961 Kwoshent

    I am Kong Fused

    3.6 years ago