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
22
G
240
Posts: 3,734
Reputation: 133,994

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
397
S
236
G
88
Posts: 24,420
Reputation: 194,549

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
22
G
240
Posts: 3,734
Reputation: 133,994

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
169
S
50
G
173
Posts: 8,319
Reputation: 110,282

Post » Fri Mar 13, 2015 5:15 am

You can, you just have to format it correctly.
ImageImageImage
B
71
S
22
G
240
Posts: 3,734
Reputation: 133,994


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests