How do I check if variable is equal to multiple numbers

  • As above, you want choose. If variable does not equal choose(1,5,8)

  • That's not what I want. As far as I know, that chooses randomly between each number.

  • Compare two values var=1|var=2|var=3|var=4 is equal to 1

    .

    Second value- 0(false); 1(true)

  • > Compare two values var=1|var=2|var=3|var=4 is equal to 1

    > .

    >

    Second value- 0(false); 1(true)

    It works, but I'd still like flameneon to help me out with the problem I was having if they get the chance

    Also, I don't really understand how this all works anyway, what exactly is happening? Can you please explain?

  • https://www.scirra.com/manual/78/expressions

    Read the operators section carefully. | is a logical OR expression. Each of the statements between the | will return 0 of false, 1 of true. So compare the whole first statement to see if you get a 0 or 1 out of it.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I can't seem to wrap my head around what 'They return 1 if the comparison is true or 0 if false.' means. Can you please elaborate for me? I'm referring to the article.

  • & = and

    | = or

    0 = false

    1 = true

    condition is true .. actions run

  • Thanks! It really should say that instead of 'return' imo. Problem solved.

  • & = and

    | = or

    0 = false

    1 = true

    condition is true .. actions run

    Thanks I didn't know '&' and '|' could be used to compare more than 1 value at once.

    I had a similar problem, I was using 'not equal' to compare.

    I tried 'make or block' and 'value1|value2'.

    The problem was the events were always triggered.

    I couldn't figure out why, I even restarted C2 to make sure I didn't find a bug.

    if value1 is not equal to apple.

    or

    if value1 is not equal to orange.

    What was happening is if one isn't true the other one will be.

    If value1 is apple, orange, or strawberry it will still trigger because at least one statement will always be true.

    I thought about using & but a variable can't be two values at once.

    I simply changed 'not equal' to 'equal' to make it work, and reorganized some of the events.

    Is there any way to compare a variable to more than one value using 'not equal' that doesn't always trigger?

    I couldn't think of a way. It would be useful to know if it were possible.

  • AND is correct. If the value is not an apple AND the value is not an orange, then it must be a strawberry.

  • I tried &, | and 'make or block' and it always triggers no matter the value I set it to.

    I just think 'not equal to' can't be used to compare more than 1 value.

    I was only curious about this.

    'Equal to' with an 'Else' works similar enough.

  • I know what you want!

    Example: if selected a,b,c,d action for all

    use right mouse button to the 1st and second condition and make or

    Example:

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)