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

Get help using Construct 2

Post » Fri May 09, 2014 8:07 am

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
B
7
S
1
Posts: 15
Reputation: 465

Post » Fri May 09, 2014 9:50 am

Hi!

Use the System Stop Loop.

Manual reference here

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

What we build can never be destroyed
B
136
S
18
G
6
Posts: 37
Reputation: 14,784

Post » Mon May 12, 2014 6:08 am

AbelaNET wrote: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
B
7
S
1
Posts: 15
Reputation: 465

Post » Mon May 12, 2014 7:10 am

by breaking up the steps I get
Snap 2014-05-12 at 08.12.45.png
You do not have the required permissions to view the files attached to this post.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
34
G
47
Posts: 1,194
Reputation: 30,892

Post » Mon May 12, 2014 12:07 pm

RamPackWobble wrote:by breaking up the steps I get
Snap 2014-05-12 at 08.12.45.png


Thanks for this RamPackWobble. It works!
B
7
S
1
Posts: 15
Reputation: 465


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 23 guests