How do I use a WHILE loop to check two conditions?

0 favourites
  • 11 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • I'm looking for something like this:

    While A is true, or B is true > do some event

    I can see how it would work with A and B being true, but not one OR the other.

    I did try using "|" and "^" but it didn't work.

  • You need to use an OR block in your event condition.

    You can right click on the far left margin on the event block and a context menu pops up, and there's an option for adding an OR to the event.

    The other way you can do it, which IMO seems more reliable anyway, is simply to double up your events and have one for each condition;

    While A is true -> do this

    -and another event below-

    While B is true -> do this

    Read more about OR blocks and other advanced features in THIS TUTORIAL

    ~Sol

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Why would you use a While in this situation ?

    A is true-->do some action

    OR

    B is true

    as long as either A or B is true the action fires so it is basically the same as , While A is true OR B is true

  • Why would you use a While in this situation ?

    A is true-->do some action

    OR

    B is true

    as long as either A or B is true the action fires so it is basically the same as , While A is true OR B is true

    I want to do the event if one or the other is true. If I check one then do the action, then I change my conditions.

    For example, I want to store a value that is not a repeat in a 3,0 array. I pick a value for 0,0, then I pick a value for 1,0 - but I need check it to make sure it's not equal to the value in 0,0 (easy to do). But then I pick a value for spot 2,0. Now that value can't be equal to the spot in 0,0 or the spot in 1,0.

    If I check 0,0, and its true (the same) then I pick a value that's not the same. BUT it might be the same as spot 1,0. If I find that it is the same as spot 1,0, I can change it so that it isn't, but now it might be equal to the value in 0,0. That's why I want to check it at once.

  • You need to use an OR block in your event condition.

    You can right click on the far left margin on the event block and a context menu pops up, and there's an option for adding an OR to the event.

    The other way you can do it, which IMO seems more reliable anyway, is simply to double up your events and have one for each condition;

    While A is true -> do this

    -and another event below-

    While B is true -> do this

    Read more about OR blocks and other advanced features in THIS TUTORIAL

    ~Sol

    When I tried an OR block, I get: While or A is true or B is true.

    And that resulted in an infinite loop, regardless if A or B was true or not.

  • I think the 'OR' block doesn't work right with while loops.

    Here's the capx file:

    https://1drv.ms/u/s!AobC4q3rBlr6ibx8L_qw4oTDgur-jw

    A counter is constantly counting up, to show that the program is running. When you hit the blue button, it checks the condition of two flags, for the while loop. On start up the conditions are set so they are not true, and we should not go into the while loop. However, you can see that the counter stops running, so we are in the while loop.

  • Here's a way you can structure it. Basically make the while and infinite loop and use the "stop loop" action to stop it.

    +--------------+
    | while        |
    +--------------+
    |  +-----------+
    |  | trueA = 0 | set trueA to 1
    +--|   -or-    | set trueB to 1
       | trueB = 0 | stop loop
       +-----------+[/code:n47tyopg]
  • Here's a way you can structure it. Basically make the while and infinite loop and use the "stop loop" action to stop it.

    +--------------+
    | while        |
    +--------------+
    |  +-----------+
    |  | trueA = 0 | set trueA to 1
    +--|   -or-    | set trueB to 1
       | trueB = 0 | stop loop
       +-----------+[/code:jsiw2xm4]
    

    I tried it, but it is still stuck in the loop. Actually, I don't think it's in the loop since I put debug text there and I never see it. I'm thinking that it's just crashing. Please take a look. This is very strange:

    capx file with your suggestion: https://1drv.ms/u/s!AobC4q3rBlr6ibx9kpuqCadUF285lA

  • Oh wait, I had the logic reversed. You want it to loop as long as either of the variables is 0, and my example only stops when one of them is zero. Add an "else" to fix it.

    +--------------+
    | while        |
    +--------------+
       +-----------+
       | trueA = 0 | set trueA to 1
       |   -or-    | set trueB to 1
       | trueB = 0 |
       +-----------+
       +-----------+
       | else      | stop loop
       +-----------+[/code:2lvl4d64]
  • Look at R0J0 with his fancy event ascii graphic event representations...

    ~Sol

  • I think the 'OR' block doesn't work right with while loops.

    Here's the capx file:

    https://1drv.ms/u/s!AobC4q3rBlr6ibx8L_qw4oTDgur-jw

    A counter is constantly counting up, to show that the program is running. When you hit the blue button, it checks the condition of two flags, for the while loop. On start up the conditions are set so they are not true, and we should not go into the while loop. However, you can see that the counter stops running, so we are in the while loop.

    OR is pretty screwy - if you're testing a value of an object in the OR statement and it fails the test, even if something else passes in the if statement, you will not be able to affect that object. It's filtered out automatically.

    You could just have a theloop=true and make the while loop check theloop to see if it's true. Inside the loop you can use multiple if statements to see if the loop should continue - if not, make theloop=false.

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