Problem with For each loop and stop loop action

Get help using Construct 2

Post » Thu Feb 19, 2015 6:59 pm

Hello,

I tested something simple. I hava a 2D array. Going through its X axis, test variable here, and stop the loop in some cases.

So :

- For each X element in array
- test variable value at x, y
- if value == 0 => do something
- else => stop loop

screen_problem.png


The system => stop loop action does not stop the iteration of the for each loop.

Am I missing something ? The stop action should prevent the iteration after it, no ?

Here's the capx :
array_problem.capx
You do not have the required permissions to view the files attached to this post.
B
13
S
4
Posts: 104
Reputation: 1,246

Post » Thu Feb 19, 2015 8:23 pm

"Stop loop" is a System object action, and will only stop loops from the System object -- for, for each, and repeat. It won't stop Array loops, since those are independent of the System object.

I'd suggest using a variable to set and detect loop completion, as follows:

Image

You might also consider making an official request for a "Stop loop" action for the Array object on the general Construct 2 board.
Moderator
B
104
S
39
G
19
Posts: 1,584
Reputation: 18,167

Post » Thu Feb 19, 2015 8:35 pm

Thank you very much linkman2004 for your help. I solved this buy using a system For loop with a variable and look at value each iteration. But the solution you provided with a variable for completion is cleaner.

I'm gonna make a request.

Nabu
B
13
S
4
Posts: 104
Reputation: 1,246

Post » Fri Jan 01, 2016 3:18 am

Just wanted to chime in and say thanks as well - I'm just learning this stuff and was stuck on the array foreach issue for a while. This solved my issue - yay!
B
3
Posts: 2
Reputation: 186

Post » Fri Jan 01, 2016 12:37 pm

linkman2004 wrote:"Stop loop" is a System object action, and will only stop loops from the System object -- for, for each, and repeat. It won't stop Array loops, since those are independent of the System object.

I'd suggest using a variable to set and detect loop completion

Even easier on the code would be using a for-loop to loop through the array, because there the stop action should work (-> you'll save some unnecessary computation).
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
20
S
9
G
1
Posts: 786
Reputation: 3,729


Return to How do I....?

Who is online

Users browsing this forum: LaroTaio, Thndr, xrosax and 11 guests