Loop Through an Array

Get help using Construct 2

Post » Fri Apr 25, 2014 5:13 pm

Hi guys,

How do I loop through an array and stop looping if a value compared of a cell is equal?

For example:

for loop.length
if cell in x is equal to `foo`
do something
STOP

:D :D :D

Here is what I have got so far.
CAPX
Last edited by KSLR on Sat Apr 26, 2014 11:34 pm, edited 1 time in total.
B
37
S
11
G
3
Posts: 279
Reputation: 8,396

Post » Sat Apr 26, 2014 11:33 pm

Hi guys, I have uploaded a CAPX with what I am trying to do. I am wondering if there is something case in construct where you can exit out of a loop when a condition is met. Ultimately I want a Plants vs Zombies tower selection mode.

CAPX
B
37
S
11
G
3
Posts: 279
Reputation: 8,396

Post » Sun Apr 27, 2014 2:59 am

https://www.scirra.com/manual/124/system-conditions
Loops can be stopped with the Stop Loop system action.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sun Apr 27, 2014 3:17 am

Not only in a array loop but any loop you can set a value in a variable ON/OFF where you just get inside of a loop when it's value is "1" and then reset (inside the loop in a sub event if necessary) to 0, then the loop won't run again.
B
56
S
21
G
3
Posts: 602
Reputation: 6,612

Post » Sun Apr 27, 2014 4:38 am

Thanks for the responses Blackhornet and kossglobal!! much appreciated attacking this problem now. :)
B
37
S
11
G
3
Posts: 279
Reputation: 8,396

Post » Tue Apr 29, 2014 5:20 am

Thanks again for the help guys.

I am having trouble populating array 1 with the contents of array 2. I am not sure what I am doing incorrectly. Could you peek into my capx? It sounds simple enough but it functions not.
B
37
S
11
G
3
Posts: 279
Reputation: 8,396

Post » Tue Apr 29, 2014 5:27 am

You've got a bunch of stuff disabled. Can you get it back to a usable state so I'm not guessing what should or shouldn't be enabled.
ImageImageImage
B
71
S
21
G
221
Posts: 3,649
Reputation: 124,227

Post » Sun May 04, 2014 6:46 am

Sorry about that black hornet. I have a new capx up there now. I fiddled around and have it populating array1 with the contents of array 2 but it populates all cells. I just want it to stop once it fills an empty slot.
B
37
S
11
G
3
Posts: 279
Reputation: 8,396

Post » Sun May 04, 2014 7:07 am

I was fiddling some more and I think I fixed it!!! hurray doing some more testing to see if I can break it. Its all in the aove capx link
B
37
S
11
G
3
Posts: 279
Reputation: 8,396


Return to How do I....?

Who is online

Users browsing this forum: adamebastin, Bro7hers and 9 guests