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
S
1
Posts: 72
Reputation: 606

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
71
S
21
G
212
Posts: 3,617
Reputation: 119,663

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
386
S
229
G
87
Posts: 24,207
Reputation: 191,742

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
71
S
21
G
212
Posts: 3,617
Reputation: 119,663

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 ImageImage
B
167
S
50
G
160
Posts: 8,178
Reputation: 103,452

Post » Fri Mar 13, 2015 5:15 am

You can, you just have to format it correctly.
ImageImageImage
B
71
S
21
G
212
Posts: 3,617
Reputation: 119,663


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go, aldi45mts and 10 guests