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

Get help using Construct 2

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


Please help, this is driving me crazy!
You do not have the required permissions to view the files attached to this post.
B
5
G
1
Posts: 10
Reputation: 545

Post » 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
Posts: 72
Reputation: 456

Post » 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
ImageImageImage
B
70
S
19
G
155
Posts: 3,384
Reputation: 90,379

Post » 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
366
S
217
G
82
Posts: 23,214
Reputation: 183,416

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

Post » Fri Mar 13, 2015 5:01 am

That is correct, but that's not what you have. You have Z = X | Y
ImageImageImage
B
70
S
19
G
155
Posts: 3,384
Reputation: 90,379

Post » 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.
Image Image
B
164
S
49
G
111
Posts: 7,620
Reputation: 77,939

Post » Fri Mar 13, 2015 5:15 am

You can, you just have to format it correctly.
ImageImageImage
B
70
S
19
G
155
Posts: 3,384
Reputation: 90,379


Return to How do I....?

Who is online

Users browsing this forum: lamar and 2 guests