How do I check if variable is equal to multiple numbers

0 favourites
From the Asset Store
More, less or equal
$15.30 USD
15% off
The game will give you a dog that appeared and you must say if he appeared more, less or equal.
  • Let's say I want to create spawn a small bunny if the variable is equal to 4, 5, 6 and 7.

    Instead of doing 4 different "If ___ variable is equal to _" events, is there a way to use just one event?

    I'm aware I can use "If ___ variable is greater than _", but what if there's an event that spawns a slightly bigger bunny if it's equal to 8? Greater than would do everything above the number, including 8.

    Hope I'm making sense. Essentially I need some sort of expression along the lines of between(3, 8) I'm not aware of any that exist.

  • Look at the Systems events there is an event called 'Is between values'. That should be what you are looking for.

  • It's for a global variable

  • Isn't that what you want?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Ah, right! Thank you, I didn't understand that's how it worked, and couldn't check because I was away from my PC at the time. I appreciate it.

  • Sorry to bring this up again! Is there an expression that goes along the lines of "If *globalvariable* is equal to 1, 2, 3, 4 then..." ?

    To further explain I want an expression that allows me to cram all the numbers I'm checking if equal to into one event, rather than doing 4 different events for each number on an Or block.

  • Cram the numbers in an 1D array. (if they are not consecutive)

    Use the condition > array > Contains value

    If they are consecutive, Asmodean showed you a 1 liner.

  • Asmodean showed me a way to check if a variable's number is in between two other values. I'm wondering if instead of:

    System: if Variable = 1

    System: if Variable = 2

    System: if Variable = 3

    System: if Variable = 4

    there's some other way of cramming it into one event, for example:

    System: if Variable = 1, 2, 3, and 4

    Is there no expression for this? By expression I mean the stuff like ceil(1, 2, 3, 4)

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

    Why not set up 4 conditions and use an "or" event block? It is still one event.

  • Also you can use compare two values 0<var&5>var is equal to 1, but again that's the same as the system is in between variables condition. Why don't the previous suggestions work for you?

  • '|' = 'or'. So, if you want check if variable equals 1,5 or 8, just write

    + System -> if Variable1 = 1 | 5 | 8|...

  • I understand that it's still one event if I use an 'Or' block, in fact I've already stated that. It all takes up so much space if I use an 'Or' block. Essentially what I want is something that doesn't take so much space. That's why I'm asking for an expression. Is there one or isn't there? That's my question.

  • '|' = 'or'. So, if you want check if variable equals 1,5 or 8, just write

    + System -> if Variable1 = 1 | 5 | 8|...

    Thank you, will try that now. I appreciate the help!

  • I think what you're looking for is choose? Maybe..

  • '|' = 'or'. So, if you want check if variable equals 1,5 or 8, just write

    + System -> if Variable1 = 1 | 5 | 8|...

    It doesn't seem to understand what numbers I'm talking about.

    System -> if Variable = '1 | 5 | 8' doesn't work

    I've confirmed it's an issue with the code not understanding what numbers I'm talking about.

    For example, if I set a bunch of bouncy balls to spawn if the variable doesn't equal '1 | 5 | 8', and then set the variable to either 1, 5 or 8, the balls still won't stop spawning. If that makes sense. Point is, it doesn't understand the number.

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