How do I do an OR inside a while?

  • Basically I want a while block to continue if any of the two conditions are present. What I currently have is this:

    This does it so that I can make sure 1 wagon isn't the same as the one just before it, but I can't check for all three. If I turn the While into an OR block, it becomes While OR numwagon.AnimationFrame.... OR numwagon2.AnimationFrame. If I don't do it, it seems to treat it as an AND.

    So how can I have an OR block INSIDE an While? Or is there some even simpler way to do this?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You could use a system->"pick by comparison"

    with an expression like:

    numwagon.animationframe=numwagon2.animationframe | numwagon.animationframe=numwagon3.animationframe[/code:3klcw15a]
  • You could use a system->"pick by comparison"

    with an expression like:

    numwagon.animationframe=numwagon2.animationframe | numwagon.animationframe=numwagon3.animationframe[/code:3mw89q1q]
    

    I'm not sure I'm understanding how "Pick by comparison" works. When I select it, I have to choose an object, expression, comparison and value. How do I do that with the code you've posted?

  • For doing it in event 2 of your pic...

    the object would be numwagon2

    The first expression would be: numwagon2.animationframe=numwagon.animationframe|numwagon2.animationframe=numwagon3.animationframe

    The comparison would be "="

    and the second expression would be 1

  • For doing it in event 2 of your pic...

    the object would be numwagon2

    The first expression would be: numwagon2.animationframe=numwagon.animationframe|numwagon2.animationframe=numwagon3.animationframe

    The comparison would be "="

    and the second expression would be 1

    It works now, thanks!

    Unfortunately, its now exposed another bug in my layout which I have to figure out. But at least now it is nicely random!

  • Hello everyone,

    Sorry to dig this old topic, but my question is in the title... and it is unsolved as far as I'm concerned :/

    R0j0's answer may be correct when the condition is related to an object, but what if it is related to a variable ?

    Simple example :

    • we are making a platformer
    • we have two variables, one reflecting the left stick direction (LStick), the other stating if the player is crouched or not (IsCrouching)
    • LStick can be set to "Up", "Down", "DownRight", "DownLeft"
    • we want to set up a loop, instead of three redundant loops, that says :

    while (LStick="Down" OR LStick="DownRight" OR LStick="DownLeft")

    then IsCrouching= "True"

    I've tried the "Pickbycomparison" but variables are not attached to an object so I don't know what to do...

    Many, maaaany thanks in advance for the one who'll be able to answer me =)

    (also, a quick side question : can you add an Else event after a While loop ? So that if the while loop is not working the IsCrouching is set to "False" again )

    Cheers

  • You don't want a loop here anyway, just an If:

    if(LStick="Down" | LStick="DownRight" | LStick="DownLeft") -> IsCrouching= "True" Else IsCrouching= "False"

    In C2, use Compare two values:

    First value: LStick="Down" | LStick="DownRight" | LStick="DownLeft"

    Comparison: Equal to

    Second value: 1

  • If you want to keep it a bit more elegant you can use the "If is true" condition from TR_System plugin.

    You can do advanced logical operations there.

  • Damn, I realized I forgot to thank you guys for your answers. Sorry.

    Thanks to your help, I realized the while loop was totally optional in my case.

  • As you already digged up this topic, I'd like to mention that there's a new TR_System condition Is value in set which makes such things even easier.

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