# How do I check if variable is equal to multiple numbers

Get help using Construct 2

### » Sun Aug 21, 2016 7:24 am

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.
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

### » Sun Aug 21, 2016 7:56 am

Look at the Systems events there is an event called 'Is between values'. That should be what you are looking for.
B
24
S
3
G
1
Posts: 451
Reputation: 2,165

### » Sun Aug 21, 2016 8:02 am

It's for a global variable
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

### » Sun Aug 21, 2016 8:14 am

Isn't that what you want?

B
24
S
3
G
1
Posts: 451
Reputation: 2,165

### » Mon Aug 22, 2016 5:30 am

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.
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

### » Thu Aug 25, 2016 8:54 am

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.
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

### » Thu Aug 25, 2016 9:06 am

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.
B
33
S
18
G
28
Posts: 2,474
Reputation: 20,912

### » Thu Aug 25, 2016 9:20 am

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)
B
24
S
10
G
1
Posts: 153
Reputation: 2,660

### » Thu Aug 25, 2016 9:34 am

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.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

### » Thu Aug 25, 2016 9:42 am

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?
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Next