0 Favourites

How do I create an AND & OR block in same event

  • What I am trying to do in a single event is this:

    if THIS1 OR (THIS2 AND THIS3) then... do something

    If I make an event an OR block then it seems I cannot create AND conditions anymore. I know how to solve this with subevents but that would require me duplicating the actions for THIS1 and then THIS2 AND THIS3.

  • If you can't put the "and" part as a sub-event to the "or" part, You can use a boolean trick.

    the following is: If This1="a" or (This2="a" and This3="a")

    Under system, use the event "Compare two values"

    First Value:

    (This1="a") + ((This2="a") * (This3="a"))

    the comparison is "Greater than or Equal"

    value to compare to is 1

    The equation in parenthesis is a boolean value, if true then the value is 1 which is what "true" equals, if it were false, the value is 0.

    So if the first field, (This1="a"), is true, it will be 1.

    If both the other are true, they both equal 1, so 1 times 1 is 1 as well. If either is false, then 1 times 0 will be 0.

    both results are added together so anything over 1 means the statement found a positive result and performs the actions.

    Does that do what you need?

  • What a great approach Paradox.

    However, the conditions I'm using aren't simple expressions - they are Keyboard and/or Touch conditions. I am, not sure if it is possible to do something like "If right arrow key is down" in the first field. So, my solution is to set a boolean every time the right arrow key is pressed. Would this be an alright solution?

  • Hmm, could you

    This1="a" | call function a

    else

    This2="a"

    This3="a" | call function a

    ?

    Use an else instead of an Or, you have to repeat the actions, but they only get called once

  • I could - I was just trying to avoid having to call the actions multiple times. Is this a limitation of C2 btw? I'm thinking OR blocks shouldn't make the entire event use OR's but instead be condition specific.

  • Badmiracle It really depends to be honest, could you give a little more context of what you are checking for the event?

    I use lots of approaches for these types of events but it really depends on what type of actions or things it is needing to check. But generally I use different variables when "something is happening or is pushed" and can use it in other events to check if it is 1 or 0, etc.

  • Djfuzion Sure. I am trying to add Mobile controls to a game that would otherwise be played on a PC using the Keyboard. So for movement I have:

    Right key is down OR (Touch.X > LayoutWidth/2 AND Is in touch) Then

    ... Do stuff for moving right

    Left key is down OR (User Touch.X < LayoutWidth/2 AND Is in touch) Then

    ... Do stuff for moving left

    etc.

    The reason I have to include "Is in touch" is because it appears that Touch.X may be true even if Is in touch is not..

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • when touch is not touching, touch.x = 0 and touch.y = 0

    so using a simple "is between values" should work in this case..

    You could ofcourse also use collodium's trick by setting a variable to 1 on touch start and back to 0 on touch end and doing something similar for the keyboard..

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