# Question about how the OR command (|) vs. OR blocks...

Discussion and feedback on Construct 2

### » Mon May 25, 2015 12:37 pm

Hi, thanks for reading my post! I'm wondering if anyone can shed some light on the OR expression using the pipe |.

I know that we can make an or block inside of a condition, for example, using "health" as a global variable:

If health = 8
OR
If health = 7

--> Display 4 hearts on HUD

But I'm looking at the OR expression and trying to figure out what's different about it. Take the same instance as above, but with:

If health = 7|8

--> Display 4 hearts on HUD

This second expression, at least from what I'm reading, should return 4 hearts on the HUD if either condition is true, i.e., if hearts are 7 OR hearts are 8. However, I've found that this second example doesn't do anything, so I'm assuming that this pipe expression is actually different from using an OR block in the condition. The construct manual says

| is a logical OR operator. These are useful combined with the comparison operators, e.g. score < 0 | health < 0, which also return 1 if true and 0 if false.

so it sounds like I can get this result using "compare 2 variables" in the system conditions as well, but not the way the second example is shown above.

Thank you!
B
24
S
6
G
1
Posts: 47
Reputation: 1,894

### » Mon May 25, 2015 12:45 pm

Deleted. Blackhornet had the right answer....
Last edited by Colludium on Mon May 25, 2015 4:58 pm, edited 1 time in total.
Learning other engines, but C2 still rocks.
B
80
S
22
G
95
Posts: 2,419
Reputation: 57,675

### » Mon May 25, 2015 1:07 pm

The format is:
System: Compare two values:
health = 7 | health = 8
= Equal to
1
B
72
S
22
G
288
Posts: 3,862
Reputation: 158,460

### » Mon May 25, 2015 7:52 pm

blackhornet wrote:The format is:
System: Compare two values:
health = 7 | health = 8
= Equal to
1

Thank you for this simple explanation! One last thing, when you say "equal to 1" , is this a universal "construct 2" thing for being active (or in this case, that the condition is true)? Or is the 1 referring to some project component we need to define ourselves?
B
24
S
6
G
1
Posts: 47
Reputation: 1,894

### » Mon May 25, 2015 9:31 pm

It's a C2 thing. True internally is 1, False internally is 0. This is a low level computer thing, actually.
B
72
S
22
G
288
Posts: 3,862
Reputation: 158,460

### » Tue May 26, 2015 9:42 am

OR blocks actually pick instances that met any of the conditions. The | operator is simply a logical OR that returns 0 or 1, based on if either operand was true (nonzero). So if you have "health = 7|8", then 7|8 is evaluated as "true OR true", which results in true, which C2 represents as 1, so it's the same as saying "health = 1" which probably wasn't what you intended!
Scirra Founder
B
414
S
245
G
92
Posts: 25,205
Reputation: 200,351

### » Tue Jun 02, 2015 12:19 am

Ashley wrote:OR blocks actually pick instances that met any of the conditions. The | operator is simply a logical OR that returns 0 or 1, based on if either operand was true (nonzero). So if you have "health = 7|8", then 7|8 is evaluated as "true OR true", which results in true, which C2 represents as 1, so it's the same as saying "health = 1" which probably wasn't what you intended!

Wow! This is definitely not what I intended. It's great to have such a welcoming community to get help with this stuff because machine logic just baffles me :-p
B
24
S
6
G
1
Posts: 47
Reputation: 1,894

Return to Construct 2 General

### Who is online

Users browsing this forum: No registered users and 3 guests