Page 1 of 1

How do loop and subevent work Together?

PostPosted: Tue Jan 13, 2015 1:59 am
by ekajuan
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?

Re: How do loop and subevent work?

PostPosted: Tue Jan 13, 2015 2:12 am
by Zoltar
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

Re: How do loop and subevent work?

PostPosted: Tue Jan 13, 2015 8:43 am
by codah
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.

Re: How do loop and subevent work Together?

PostPosted: Tue Jan 13, 2015 8:57 am
by codah
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.

Re: How do loop and subevent work Together?

PostPosted: Tue Jan 13, 2015 9:14 am
by steveb25
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.

Re: How do loop and subevent work Together?

PostPosted: Tue Jan 13, 2015 1:48 pm
by brunopalermo
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.