Quick "For Each" question

For questions about using Classic.

Post » Tue Aug 24, 2010 11:32 am

I just want to know that if I have an event like this:

Sprite: X greater than 0
For each Sprite


Will Construct only run the For Each loop for the Sprites with X greater than 0 or does it always cycle through every single instance of the Sprite?
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

Post » Tue Aug 24, 2010 11:41 am

It will pick all the sprites with x > 0.

You can add more conditions under the loop for loop specific refinements
eg.

@For each sprite
PV "something" = n -> do stuff

If you put the other condition above the for each, Construct will pick all of those first, and then do the for each. I don't know if it makes much difference, but I find it to be more reliable if the conditions are under the loop.
B
2
G
2
Posts: 42
Reputation: 734

Post » Tue Aug 24, 2010 11:46 am

I was just thinking if it would work towards better performance. I don't have performance issues yet, but might as well take precautions.
B
5
S
2
G
3
Posts: 234
Reputation: 1,818

Post » Tue Aug 24, 2010 12:20 pm

I used to do that too until I read the wiki page on optimising.

My project is usually at about 70-80% CPU waiting, so as the tutorial explains, improving CPU efficiency in events isn't going to amount to anything.

This sort of problem is better left to the pros, I surmised :).
B
2
G
2
Posts: 42
Reputation: 734

Post » Tue Aug 24, 2010 2:47 pm

Here's a detailed explanation of how for each works: viewtopic.php?f=8&t=6185
Moderator
B
88
S
32
G
33
Posts: 3,005
Reputation: 27,432


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 0 guests