# How do I Compare A Variable to a Range of Numbers

Get help using Construct 2

### » Wed Dec 17, 2014 6:25 pm

Example:

Code: Select all
`var "a" = 32 or 37 or 38 or 39 or 40{Do something() }`

So if a variable is equal to one of those numbers, something happens.

EDIT: I'm looking for one line solution, not making "or" or adding more conditions.
Last edited by Android-Music on Wed Dec 17, 2014 7:08 pm, edited 1 time in total.
B
81
S
23
G
6
Posts: 240
Reputation: 7,786

### » Wed Dec 17, 2014 6:32 pm

Right-click the event and choose "Make 'Or' Block", then add all conditions that apply.

or-block.png
You do not have the required permissions to view the files attached to this post.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

### » Wed Dec 17, 2014 7:06 pm

Nah, sorry, that's not what am I looking for, one line solution is the aim.
B
81
S
23
G
6
Posts: 240
Reputation: 7,786

### » Wed Dec 17, 2014 7:13 pm

Use "Compare two vales", a=32 | a=37 "Equal to" 1
B
71
S
22
G
274
Posts: 3,829
Reputation: 151,306

### » Wed Dec 17, 2014 7:22 pm

Not gonna happen.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

### » Wed Dec 17, 2014 7:30 pm

@blackhornet , that's quite an interesting solution, will try that for sure, thanks a lot!

EDIT: wow it really works, thanks again!
B
81
S
23
G
6
Posts: 240
Reputation: 7,786

### » Wed Dec 17, 2014 8:17 pm

If you want to be clever you could do this too:
find(",32,37,38,39,40,", ","&a&",") >=0

Or you could make a function if you plan on doing something like that more than once:

on function "one of em"
for "" from 1 to Function.ParamCount-1
function: parameter 0 = Function.Param(loopindex)

Then you can use it with:
System: compare Function.call("one of em", a, 32, 37, 38, 39, 40) = 1
B
95
S
34
G
128
Posts: 5,497
Reputation: 81,682

### » Wed Dec 17, 2014 8:24 pm

Nice solution R0J0hound! O.o
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
22
S
6
G
3
Posts: 717
Reputation: 3,996

### » Wed Dec 17, 2014 8:33 pm

Thanks @R0J0hound , this solution is great too!
B
81
S
23
G
6
Posts: 240
Reputation: 7,786