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

0 favourites
  • 7 posts
From the Asset Store
In this game you will command the character by voice command.
  • 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:

    [quote:z7vo2xe1]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:

    [quote:z7vo2xe1]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

    [quote:z7vo2xe1]| 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!

  • Deleted. Blackhornet had the right answer....

  • The format is:

    System: Compare two values:

    health = 7 | health = 8

    = Equal to

    1

  • 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?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It's a C2 thing. True internally is 1, False internally is 0. This is a low level computer thing, actually.

  • 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!

  • 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

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)