Add a condition inside a loop?

Discussion and feedback on Construct 2

Post » Wed Jul 27, 2011 5:59 pm

Rightclick on a loop -> add condition makes the loop check a condition every time and if its true, an action can occur.

I need to check multiple conditions inside one loop, and add an action for EVERY SINGLE condition, not for the whole set of true conditions. So i dont need to create new loops for every condition to be true too.

Could someone explain me how to do that, maybe inside a small capx?xeed2011-07-27 18:01:43
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Wed Jul 27, 2011 6:03 pm

Have the loop condition as a "master" event, and then add as much sub-events as you need, with each its own set of conditions and actions.
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Wed Jul 27, 2011 6:09 pm

I'd try this, but the sub-events seem to stay true forever. I got flooded with new sprites.

I thought the conditions would make this thing being checked only once every loopindex. If i should use events for checking if/else parameters, whats the sense of conditions?
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Wed Jul 27, 2011 6:13 pm

Sub-events are executed once every iteration, isn't it what you want ?
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Wed Jul 27, 2011 6:29 pm

It is.

I need to check the angle for each sprite. If it is 0-1 another action should happen as when the angle is 90-91.
I tried as condition inside the for-each loop, but this puts an action for all conditions.
When i use a sub-event, the action does not only happen every iteration, it happens like i dont use subevents. It occurs like a normal event in root.

May this be a bug in r50?
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Wed Jul 27, 2011 6:47 pm

You don't need a "for each" sprite loop. An event "Is between angle" will automaticly check EVERY instances of the sprite.

So put a serie of events Sprite."Is between angle" testing from 0 to 90, another from 91 to 180, a third one from 181 to 270 and a last one from 271 to 360, and for each event you will have an action that will only happen when the condition is true.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Wed Jul 27, 2011 7:07 pm

If you use the For each to loop for every instance of an object, then do as Kyatric said. You have to make use of the implicit looping when you can !
B
46
S
17
G
18
Posts: 847
Reputation: 13,802

Post » Wed Jul 27, 2011 8:25 pm

I rebuild the project, now it works fine in a for-each loop with sub-events.


[QUOTE=Kyatric] ... and for each event you will have an action that will only happen when the condition is true.[/QUOTE]

While or when? I guess the action is performed every frame and continue as i dont check the angle in a loop.

If not, I still need to learn few (strange) stuff about c2
B
15
S
3
G
5
Posts: 396
Reputation: 4,977

Post » Wed Jul 27, 2011 9:00 pm

New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795


Return to Construct 2 General

Who is online

Users browsing this forum: Cryptwalker, pablo7 and 13 guests