[Solved]For each and Trigger Once looping

Get help using Construct 2

Post » Thu Mar 07, 2013 4:14 pm

I get a headache on this. They seems don't like each other and it keeping spawning of objects.

porky2013-03-08 08:50:05
B
14
S
2
G
1
Posts: 94
Reputation: 2,089

Post » Thu Mar 07, 2013 4:49 pm

Do you want to stop the loop as soon as one spawning event has occured ? If so, remove the "Trigger once" and add a "Stop loop" action.
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Thu Mar 07, 2013 5:05 pm

@Magistross, I tried the way you said, not working:(
B
14
S
2
G
1
Posts: 94
Reputation: 2,089

Post » Thu Mar 07, 2013 5:11 pm

Hmmm, I think I misunderstood what you wanted. You want your whole loop to trigger only once. When do you want it to fire, on the start of the layout ?
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Thu Mar 07, 2013 5:12 pm

Hm i have a similar kind of event in my isometric Z-ordering example. I have tiles that each spawn a certain number of objects on top of themselves to stack blocks up. I got it to stop spawning using a trigger once event.

Its for a different purpose but this might help:
example capx
B
14
S
4
G
3
Posts: 38
Reputation: 3,741

Post » Thu Mar 07, 2013 6:00 pm

Thanks for helping:)

@Magistross: My goal is trigger this event ONCE(1 loop for each) at anytime when the condition matches.

@Tommyttk: I find in your example the "Trigger Once" is in front of "For Each", which is the magic make it works! but It is only trigger once in the whole game/layout. What if I want re-trigger this when the condition matches?

B
14
S
2
G
1
Posts: 94
Reputation: 2,089

Post » Thu Mar 07, 2013 6:06 pm

[QUOTE=porky] I find in your example the "Trigger Once" is in front of "For Each", which is the magic make it works! but It is only trigger once in the whole game/layout. What if I want re-trigger this when the condition matches?

[/QUOTE]

You'll need to put it under event that is the condition you mention there. Generic method would be:

global variable RUN_LOOP = 0

RUN_LOOP = 1
..your loop here
... your loop action stuff
.. RUN_LOOP = 0

Now, whenever you wish to run that loop you can set RUN_LOOP to 1 in your events. That's the generic way, better way is making your loop a function. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,202

Post » Thu Mar 07, 2013 8:21 pm

Thanks for the hint! I eventually find the way:) It's basically same as Vee41 said, but since I have a lot of instances, so instead of global variable. I use instance variable and it finally worked!
Here is the working example:


Thanks again:)
B
14
S
2
G
1
Posts: 94
Reputation: 2,089


Return to How do I....?

Who is online

Users browsing this forum: Google [Bot], kamens503, Yahoo [Bot] and 25 guests