How do I use For Each?

Get help using Construct 2

Post » Tue Mar 18, 2014 7:35 pm

Has anyone actually figured out how this condition works? I know you use it for multiple instances of the same sprite, but it always seems to require hours of headaches moving "for each" to different events to see its effects.

And even then, I'm still able to figure out a bug (ie. if you DONT kill the first enemy and move past him, the second one wont do what it's supposed to)

All I've figured out is that when picking instances via instance variables/booleans, anytime you use Else, it disables the picking. Can anyone shed some insight on this? Thanks.
B
42
S
12
G
1
Posts: 540
Reputation: 4,213

Post » Tue Mar 18, 2014 7:50 pm

@ome6a1717 - I usually use "For Each" with object families.
B
33
S
7
G
8
Posts: 312
Reputation: 8,528

Post » Tue Mar 18, 2014 7:58 pm

after a lot of headaches i found a reply post from ashley that explained the situation.
all system conditions do not pick instances.(compare,trigger once ,else etc) so you need to add a " for each"
everything else, he has programmed it to automatically pick instances. it has a build in "for each" so no need to add one.
hope i cleared things up
B
15
S
6
G
4
Posts: 277
Reputation: 3,948

Post » Tue Mar 18, 2014 8:03 pm

The for each conditions is something that can be used when you are using a condition that does not pick any object (for exemple: compare two values) so you can pick all of them at once.

The Else does not pick any object (cf. manual), so it will mostly compare for the oldest instance by default, but I think you can do without it in most cases (compare the other value of a boolean for exemple, etc..), I always try to make it that C2 take care of the picking.

in fact, I use it only when it happens that I need it, which does rarely for me.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Mar 18, 2014 8:11 pm

@Roccinio, right - thats how I've been using my for each's, but I seem to find bugs every time.

For instance, one of the issues I'm having right now:

Player.Y < Enemy.InstanceVariable
For Each Sprite

DO THIS

Else
Player.Y >Enemy.InstanceVariable
For Each Enemy

DO THIS

Since it's not actually picking each individual enemy instance, it requires a for each.
B
42
S
12
G
1
Posts: 540
Reputation: 4,213

Post » Tue Mar 18, 2014 8:12 pm

@Aphrodite - I completely understand that. That's why I'm baffled what I'm doing isn't working properly.

Does it matter when the for each is taken into account? Should it be a sub-event of the instance pick, or with the instance pick event; above or below?
B
42
S
12
G
1
Posts: 540
Reputation: 4,213

Post » Tue Mar 18, 2014 8:20 pm

ome6a1717 wrote:@Aphrodite - I completely understand that. That's why I'm baffled what I'm doing isn't working properly.

Does it matter when the for each is taken into account? Should it be a sub-event of the instance pick, or with the instance pick event; above or below?


it matters, In your case I think you have to use it before the comparaison
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Tue Mar 18, 2014 8:30 pm

yes use for each before and then add subevent the rest

for each "sprite"
.................compare 2 values------------------------------->then do something
B
15
S
6
G
4
Posts: 277
Reputation: 3,948

Post » Tue Mar 18, 2014 8:49 pm

Moderator
B
95
S
34
G
33
Posts: 3,007
Reputation: 27,876

Post » Tue Mar 18, 2014 11:40 pm

@Arima - nice tutorial. It helped a bit, but I'm still having issues when multiple enemies are on screen (however all of your advice helped when you DONT kill an enemy and get to the next one)

Hm. As far as I can tell, I'm doing this right. Can anyone point out any visible issues?

Image
B
42
S
12
G
1
Posts: 540
Reputation: 4,213

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 6 guests