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
19
G
179
Posts: 3,478
Reputation: 102,672

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
378
S
220
G
84
Posts: 23,863
Reputation: 188,019

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
19
G
179
Posts: 3,478
Reputation: 102,672

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
164
S
49
G
138
Posts: 7,953
Reputation: 91,872

Post » Fri Mar 13, 2015 5:15 am

You can, you just have to format it correctly.
ImageImageImage
B
71
S
19
G
179
Posts: 3,478
Reputation: 102,672


Return to How do I....?

Who is online

Users browsing this forum: Alex Bryant, Aquanex2, Congrats2u, Moordhuis, omnipaws, tarek2 and 11 guests