For Each Object

For questions about using Classic.

Post » Sat Dec 27, 2008 11:54 am

Is there a way to stop the loop of 'for each object'?
Say I want it to run through all the objects of a type only once.

I want to go through all objects of a type so I could assign different values to them. But it only need to be run once and not looping through the whole game.

Is there a way to stop it? I tried puting it on a group or in a function, but I'm not sure if it worked.

Or are there alternatives?
B
16
S
10
G
5
Posts: 255
Reputation: 3,934

Post » Sat Dec 27, 2008 12:03 pm

You could try this:

For each
Trigger once : action
B
2
S
1
G
4
Posts: 71
Reputation: 1,342

Post » Sat Dec 27, 2008 12:07 pm

The best ways are to put it in a group which you then disable, to put it in a subevent of a function, or the subevent of an event which will only trigger once.
B
3
S
2
G
5
Posts: 1,777
Reputation: 5,529

Post » Sat Dec 27, 2008 3:29 pm

Just put a condition above it that decides when to run the loop. Because conditions are read in top-to-bottom order, if conditions above the for each loop are false, it won't reach the for each loop.

In Porlo's case you'd actually want to do

+ Trigger once
+ For each ...

Or maybe

+ Start of layout
+ For each ...

(Putting trigger once below the loop has no effect, because things below the loop are repeated once for each iteration of the loop)
Scirra Founder
B
359
S
214
G
72
Posts: 22,946
Reputation: 178,468

Post » Sat Dec 27, 2008 4:01 pm

Thanks Ashley, that actually worked.. I was putting the Trigger Once below that didn't work.
I noticed the speed difference.
B
16
S
10
G
5
Posts: 255
Reputation: 3,934


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 5 guests