How do I check if variable is equal to multiple numbers

Get help using Construct 2

Post » 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
22
S
8
Posts: 5
Reputation: 1,875

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

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

Post » 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
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

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

Post » Thu Aug 25, 2016 10:56 am

As above, you want choose. If variable does not equal choose(1,5,8)
B
45
S
15
G
73
Posts: 2,006
Reputation: 43,394

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

Post » Thu Aug 25, 2016 11:17 am

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



Image

Second value- 0(false); 1(true)
Image
B
64
S
23
G
7
Posts: 1,481
Reputation: 10,823

Post » 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
.



Image

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

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

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: DjowG, ramyaswetha and 8 guests