If statement inside loop

Get help using Construct 2

Post » Tue Jan 13, 2015 1:57 am

Does Construct 2 support If statements inside Loops ?
How do I implement it ?
Please give an example, thanks in advance.
B
5
S
1
Posts: 22
Reputation: 417

Post » Tue Jan 13, 2015 1:09 pm

Of course - normal events are like if statements, so just put a normal event inside a loop. See How events work
Scirra Founder
B
402
S
238
G
89
Posts: 24,644
Reputation: 196,095

Post » Tue Jan 13, 2015 1:25 pm

Zoltar wrote:Does Construct 2 support If statements inside Loops ?
How do I implement it ?
Please give an example, thanks in advance.

To the best of my knowledge - events (and sub-events) ARE if statements.
B
5
Posts: 24
Reputation: 280

Post » Tue Jan 13, 2015 1:29 pm

Make the loop event. Right click it and add a blank sub event. Then in the sub event add your condition event.
ImageImageImageImageImage
B
19
S
5
G
1
Posts: 614
Reputation: 2,542

Post » Tue Jan 13, 2015 10:20 pm

I've made a little test with a new project:

13-01-2015 04-33-27.png


the "inc" variable should stop at 9 but it continues to be incremented by 1.
What's wrong here ?
You do not have the required permissions to view the files attached to this post.
B
5
S
1
Posts: 22
Reputation: 417

Post » Tue Jan 13, 2015 11:01 pm

Zoltar wrote:I've made a little test with a new project:

13-01-2015 04-33-27.png


the "inc" variable should stop at 9 but it continues to be incremented by 1.
What's wrong here ?


Interesting. I see the same result. The loop sub-event seems to get evaluated independently of the parent loop completion. So the increment is forever, in this test. Seems like a bug to be logged.
B
14
S
4
Posts: 300
Reputation: 1,643

Post » Tue Jan 13, 2015 11:01 pm

Zoltar wrote:I've made a little test with a new project:

13-01-2015 04-33-27.png


the "inc" variable should stop at 9 but it continues to be incremented by 1.
What's wrong here ?


I answered this for you in another thread.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Jan 13, 2015 11:04 pm

C2 runs your events in a loop itself! It does not run once and end. You have to manage your logic around how the engine works.
ImageImageImage
B
71
S
22
G
258
Posts: 3,791
Reputation: 143,198


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 8 guests