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

Get help using Construct 2

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

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

+ System -> if Variable1 = 1 | 5 | 8|...
B
24
S
10
Posts: 5
Reputation: 2,030

### » Thu Aug 25, 2016 10:10 am

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.
B
30
S
12
G
1
Posts: 167
Reputation: 3,038

### » Thu Aug 25, 2016 10:10 am

flameneon wrote:'|' = '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!
B
30
S
12
G
1
Posts: 167
Reputation: 3,038

### » Thu Aug 25, 2016 10:14 am

I think what you're looking for is choose? Maybe..
Last edited by plinkie on Thu Aug 25, 2016 11:45 am, edited 1 time in total.
B
52
S
21
G
92
Posts: 2,404
Reputation: 54,496

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

flameneon wrote:'|' = '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.
B
30
S
12
G
1
Posts: 167
Reputation: 3,038

### » Thu Aug 25, 2016 10:56 am

As above, you want choose. If variable does not equal choose(1,5,8)
B
52
S
21
G
92
Posts: 2,404
Reputation: 54,496

### » Thu Aug 25, 2016 10:58 am

That's not what I want. As far as I know, that chooses randomly between each number.
B
30
S
12
G
1
Posts: 167
Reputation: 3,038

### » Thu Aug 25, 2016 11:17 am

oosyrag wrote:Compare two values var=1|var=2|var=3|var=4 is equal to 1
.

Second value- 0(false); 1(true)
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,104

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

korbaach wrote:
oosyrag wrote: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?
B
30
S
12
G
1
Posts: 167
Reputation: 3,038

### » Thu Aug 25, 2016 3:58 pm

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.
B
60
S
30
G
131
Posts: 1,925
Reputation: 73,827

PreviousNext