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

Get help using Construct 2

Post » Sat Jun 25, 2016 2:52 pm

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.
B
11
S
3
Posts: 52
Reputation: 791

Post » Sat Jun 25, 2016 3:42 pm

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
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Post » Sat Jun 25, 2016 3:46 pm

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
What I know would fill a Book , what I don't know would fill a Library
B
37
S
12
G
29
Posts: 331
Reputation: 16,499

Post » Sat Jun 25, 2016 3:54 pm

granpa wrote: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.
B
11
S
3
Posts: 52
Reputation: 791

Post » Sat Jun 25, 2016 4:00 pm

SoldjahBoy wrote: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.
B
11
S
3
Posts: 52
Reputation: 791

Post » Sat Jun 25, 2016 4:33 pm

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.
Last edited by COGames on Sun Jun 26, 2016 12:05 am, edited 1 time in total.
B
11
S
3
Posts: 52
Reputation: 791

Post » Sat Jun 25, 2016 6:10 pm

Here's a way you can structure it. Basically make the while and infinite loop and use the "stop loop" action to stop it.
Code: Select all
+--------------+
| while        |
+--------------+
|  +-----------+
|  | trueA = 0 | set trueA to 1
+--|   -or-    | set trueB to 1
   | trueB = 0 | stop loop
   +-----------+
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Sun Jun 26, 2016 12:01 am

R0J0hound wrote:Here's a way you can structure it. Basically make the while and infinite loop and use the "stop loop" action to stop it.
Code: Select all
+--------------+
| while        |
+--------------+
|  +-----------+
|  | trueA = 0 | set trueA to 1
+--|   -or-    | set trueB to 1
   | trueB = 0 | stop loop
   +-----------+


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
B
11
S
3
Posts: 52
Reputation: 791

Post » Sun Jun 26, 2016 12:55 am

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.

Code: Select all
+--------------+
| while        |
+--------------+
   +-----------+
   | trueA = 0 | set trueA to 1
   |   -or-    | set trueB to 1
   | trueB = 0 |
   +-----------+
   +-----------+
   | else      | stop loop
   +-----------+
B
92
S
32
G
107
Posts: 5,280
Reputation: 69,971

Post » Sun Jun 26, 2016 3:56 am

Look at R0J0 with his fancy event ascii graphic event representations... :D

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
83
S
34
G
40
Posts: 3,032
Reputation: 30,474

Next

Return to How do I....?

Who is online

Users browsing this forum: atmas, Bootfit, Freak Workshop and 28 guests