[solved] How do I loop properly through an array?

Get help using Construct 2

Post » Fri Jun 20, 2014 11:42 am

Hi all,

whatever I try, I am totally blocked with looping through an array (read the manual, tutorials and others posts, but nothing helped me).

This is how my loop is set up:
loopissue.png


I added the loops variable to see, if the loop is running at all, and I can see that it only runs 1 time.

Dimensions are:
x=100
y=100
z=1

Any idea, why this does not work?
You do not have the required permissions to view the files attached to this post.
Last edited by Ubivis on Fri Jun 20, 2014 12:09 pm, edited 1 time in total.
B
44
S
10
G
8
Posts: 437
Reputation: 6,463

Post » Fri Jun 20, 2014 12:04 pm

The System -> For Each condition runs once for every instance of the Object Type you pick. In that particular case case you are making the event loop through all your Array instances (of which you only have one). If you wish to loop through the array elements, you have two options:

Use the Array -> For Each XY element condition (you can use the Array.CurValue, Array.CurX and Array.CurY expressions within the event to access the current element, current x index and current y index respectively)

Use two nested System -> For events from 0 to 99 and access the elements using the Array.At expression with loopindex like so:

System -> For "X" from 0 to 99
System -> For "Y" from 0 to 99
........ Do something with Array.At(loopindex("X"), loopindex("Y"))
B
6
S
2
Posts: 79
Reputation: 608

Post » Fri Jun 20, 2014 12:09 pm

thank you very much @monitz87, just did that after I posted my request :D
Working fine now.
B
44
S
10
G
8
Posts: 437
Reputation: 6,463


Return to How do I....?

Who is online

Users browsing this forum: Baidu [Spider] and 38 guests