Problem with For each loop and stop loop action

0 favourites
  • 5 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • 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

    [attachment=1:q1x0vq5p][/attachment:q1x0vq5p]

    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 : [attachment=0:q1x0vq5p][/attachment:q1x0vq5p]

  • "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:

    You might also consider making an official request for a "Stop loop" action for the Array object on the general Construct 2 board.

  • 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

  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • "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).

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)