How do I Exit a Loop - without executing all loop actions?

0 favourites
  • 5 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hi Guys,

    Representation of my Loop Problem:

    Variable X,Y,Z = 0

    Condition 1: Repeat 10 Times

    Condition 2: Y < 100

    Add to X 20

    Add to Y 50

    Add to Z 100

    What I want is to exit the loop when Y becomes 100, without executing the 3rd Action (Add to Z 100)

    The Desired result is:

    X= 40 (Action Add to X Executed twice)

    Y=100 (Action Add to Y Executed twice before the condition fails)

    Z= 100 (Action Add to Z executed once since the condition failed)

    The Result I get from Construct2:

    X=40

    Y=100

    Z= 200 (All 3 actions in the loop were completely executed before checking for the condition)

    I have tried different approaches- None of them worked:

    1. Outside loop, I've set System Event to "Stop Loop" if Y >=100

    2. Outside loop, I've set System Event to "Deactivate Group" in which loop is if Y >=100

    Now I understand that all the actions will be performed before checking the condition for loop.

    My Question is : Is there a way to exit the loop without performing all actions when a condition is met. To solution I'm looking for is as follows:

    Repeat 10 Times

    Add to X 20

    Add to Y 50

    IF Y >= 100 Exit Loop

    Add to Z 100

    Is this possible through Construct2? Or do I have to code it in Javascript in C2runtime.js?

    This is simplistic representation of the problem I have at hand. I want to apply this logic to show user's friends' photos dynamically in a facebook game.

    Any help will be much appreciated.

    Thank you.

    Capper33

  • Hi!

    Use the System Stop Loop.

    Manual reference here

    https://www.scirra.com/manual/125/system-actions

  • Hi!

    Use the System Stop Loop.

    Manual reference here

    https://www.scirra.com/manual/125/system-actions

    Hi AbelaNET,

    Thanks for the suggestion. I have gone through the manual.

    I have also mentioned in my post that I have used "stop loop". It did not work for me.

    I think stop loop will stop the next iteration of the loop. It will not stop executing the commands in between.

    Cheers,

    Capper

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • by breaking up the steps I get

    [attachment=0:1xl3ybpu][/attachment:1xl3ybpu]

  • by breaking up the steps I get

    [attachment=0:1w5g6hb4][/attachment:1w5g6hb4]

    Thanks for this RamPackWobble. It works!

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