How do loop and subevent work Together?

Get help using Construct 2

Post » Tue Jan 13, 2015 1:59 am

If I use a loop:
for x from 1 to 4
and I have a subevent below it
how does the flow go?
Is it executing the parent's event 4 times, then it goes to the subevent?
or every x it will execute the parent and the subevent?
---------------------------------------------------
If I use WHILE condition and other condition,
is it the same if I use WHILE with a subevent?
Last edited by ekajuan on Tue Jan 13, 2015 4:12 am, edited 1 time in total.
B
10
S
5
Posts: 220
Reputation: 1,464

Post » Tue Jan 13, 2015 2:12 am

Yep, the same question by me, this is where i'm stuck right now.
How the flow of sub-event goes inside a loop ?

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


This example isn't working, index just keeps increasing by 1 endlessly
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 8:43 am

Zoltar wrote:Yep, the same question by me, this is where i'm stuck right now.
How the flow of sub-event goes inside a loop ?

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


This example isn't working, index just keeps increasing by 1 endlessly


Your entire loop is running maybe 60 times a second. You need a condition to make it only run once. Like a "System: Once while true" above it, or put it under "on start of layout", etc.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Jan 13, 2015 8:57 am

ekajuan wrote:If I use a loop:
for x from 1 to 4
and I have a subevent below it
how does the flow go?
Is it executing the parent's event 4 times, then it goes to the subevent?
or every x it will execute the parent and the subevent?
---------------------------------------------------
If I use WHILE condition and other condition,
is it the same if I use WHILE with a subevent?


Having subevents under a loop doesn't alter the way the subevents work, they are just repeatedly executed as per the loop conditions.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Tue Jan 13, 2015 9:14 am

I had the same problem, as I was trying to use code from languages such as Python..

The easiest way I have found is to use the loopindex as the controlling factor and check to see if that has reached the upper value of the loop.
B
8
S
1
Posts: 9
Reputation: 487

Post » Tue Jan 13, 2015 1:48 pm

You don't have to check anything. But you MUST use the loop inside an event like Every X seconds or another condition. Because using kjust the loop means that every tick the loop will be run again forever.
Bruno

I like to eat, but I'm no cook. Why liking to play games would make you a game designer?
B
19
S
5
G
1
Posts: 530
Reputation: 2,727


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 34 guests