is there an equation that will return 1 for a certain number and 0 for anything else?

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.
  • is there an equation that will return 1 for a certain number and 0 for anything else? So, say I want to test whether some value is equal to 47, but I want to be able to do it right inside an expression, rather than as a separate condition - is there some way to make an equation turn 47 into 1, while any other number will result in 0? Perhaps using one of the bitwise operators or something?

    I've been using the Immediate If object for this (ie. to squeeze a condition inside an expression) but if there's a mathematical and extension-less way I think I'd prefer to use that.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

  • Code
    Floor(( 2.7183 pow ( -1 * ( ( Value - 47 ) pow 2 ) ) ))

    Normal distribution.

    Whoa this is cool - is 2.7183 a constant that works for every value or did you derive it from the target 47 somehow

    edit: ah, that's eulers number. woops, been a couple decades since I last looked at it and wondered why it was familiar

  • Code
    Floor(( 2.7183 pow ( -1 * ( ( Value - 47 ) pow 2 ) ) ))

    Normal distribution.

    That's like magic XD

    I don't trust myself to remember to type it correctly though. But seeing this gave me some ideas of slightly simpler ways of doing it. Seeing you use pow got me thinking in that direction, and I thought this might get me there:

    Code
    ( Value - 47 ) pow 0

    In Excel, this returns 1 for all wrong numbers, and a #num error for the right number. I hoped that in Fusion it would simply return a 0 for the right number. Though actually just returns 1 for everything. But I ended up with this, which is still relatively short (and will be easier for me to remember than the Euler's number-based one):

    Code
    ( ( Value - 47 ) / ( Value - 47 ) ) xor 1

    If the number is correct (47) it will produce a divide-by-zero scenario, which Fusion graciously turns into an error-free zero. That gives 1 for all the wrong numbers, and 0 for the right one. The XOR 1 then flips that around, so all the 1s become 0s and 0 becomes 1.

    Thanks for your help, guys :)

    [MENTION=30815]Progject[/MENTION]: I started answering your question about Spryke, but eventually turned it into its own post on the Please login to see this link.:)

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

  • Code
    ( ( Value - 47 ) / ( Value - 47 ) ) xor 1

    If the number is correct (47) it will produce a divide-by-zero scenario, which Fusion graciously turns into an error-free zero. That gives 1 for all the wrong numbers, and 0 for the right one. The XOR 1 then flips that around, so all the 1s become 0s and 0 becomes 1.

    If you'd like to get rid of the brackets, this also pretty much does the same thing:

    Code
    (1 - a xor b / a xor b)

    Operations in order:
    - Highest priority: xor gives 0 if both left and right values are the same.
    - Second highest: division gives 1 if both left and right values are the same except for 0.
    - Last: subtraction inverses the result so that equality is 1 and inequality is 0.

    where a and b are your values that you want to check for equality.

    - BartekB

    Join the Click Converse Discord! - Please login to see this link.

  • Thanks BartekB! I definitely appreciate having fewer brackets. Many of my expressions are complicated enough already, without adding another bunch of brackets to make it even harder to follow. I love that your solution is self-contained in a single set of brackets. I'll use this formula for sure.

    Please login to see this link.
    My Fusion Tools: Please login to see this link. | Please login to see this link. | Please login to see this link.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!