# How do I use the OR "|" operator properly?

Get help using Construct 2

### » Thu Mar 12, 2015 5:08 am

I have been trying to make use of the OR operator in my game, but it doesn't seem to be working correctly.

It would appear that it is only checking the first parameter and not looking at the second one.
When the second parameter is true in my game (eg. the one after the "|" symbol), the action is not happening.

Chords.png

You do not have the required permissions to view the files attached to this post.
B
5
G
1
Posts: 10
Reputation: 545

### » Thu Mar 12, 2015 6:09 am

try this: right click on any block and toggle on Make 'or' block function. Now all conditions in this block will be separated by OR (not by AND as by default)
B
8
S
1
Posts: 72
Reputation: 606

### » Thu Mar 12, 2015 6:19 am

You are ORing the data, not comparing if the data is A or the data is B. The pattern is:
System:Compare two values
First value: Z=A | Z=B
Comparison: Equal to
Second value: 1
B
71
S
22
G
288
Posts: 3,859
Reputation: 158,424

### » Thu Mar 12, 2015 10:42 am

The | is a logical OR operator. It deals only with true or false values. IIRC a non-empty string counts as true, so "C#"|"Db" will always return true (1), and then you compare the array value to 1.
Scirra Founder
B
414
S
245
G
92
Posts: 25,198
Reputation: 200,327

### » Fri Mar 13, 2015 3:09 am

blackhornet wrote:You are ORing the data, not comparing if the data is A or the data is B. The pattern is:
System:Compare two values
First value: Z=A | Z=B
Comparison: Equal to
Second value: 1

What do you mean by ORing the data? I'm still really confused by the whole OR operator thing. Can someone really dumb it down for me?

I was thinking it worked such as [ Z = X | Z = Y ] return "1" if either is true, or return "0" if neither is true.
B
5
G
1
Posts: 10
Reputation: 545

### » Fri Mar 13, 2015 5:01 am

That is correct, but that's not what you have. You have Z = X | Y
B
71
S
22
G
288
Posts: 3,859
Reputation: 158,424

### » Fri Mar 13, 2015 5:12 am

It would be nice if we could do that, rather than have to use the condition "or"s.
B
178
S
50
G
206
Posts: 8,684
Reputation: 127,711

### » Fri Mar 13, 2015 5:15 am

You can, you just have to format it correctly.
B
71
S
22
G
288
Posts: 3,859
Reputation: 158,424