# Order of operations for loops

Discussion and feedback on Construct 2

### » Thu Apr 27, 2017 7:49 pm

Has the order of operations changed?
https://www.dropbox.com/s/veyunu06021qb ... .capx?dl=0

In the capx I have a nested loop x, and y
On the first layout the object is created at y loopindex, and the x loopindex, and is created in columns.
Run debug to test.

On the second it's created at x loopindex, and y loopindex , and goes in rows.

I always thought it was the other way around where x, then y made rows.
B
175
S
50
G
199
Posts: 8,625
Reputation: 124,026

### » Thu Apr 27, 2017 7:59 pm

Check the active event sheet for each layout.... We've all been there!
Learning Unity, but C2 still rocks.
B
78
S
20
G
92
Posts: 2,407
Reputation: 55,901

### » Thu Apr 27, 2017 8:28 pm

Sorry, it should be correct now, otherwise just link 1 to 1, 2 to 2.

Still sure something's changed with loops however.
B
175
S
50
G
199
Posts: 8,625
Reputation: 124,026

### » Thu Apr 27, 2017 8:39 pm

Mmmm - at first it made no sense when I changed the primary event sheet for No 2, but I think there was a browser cache problem. It appears to be working correctly for me now...
Learning Unity, but C2 still rocks.
B
78
S
20
G
92
Posts: 2,407
Reputation: 55,901

### » Thu Apr 27, 2017 9:02 pm

I've updated the capx to illustrate the difference with some text.
B
175
S
50
G
199
Posts: 8,625
Reputation: 124,026

### » Thu Apr 27, 2017 9:46 pm

Its always been like this?

X is "horizontal" (rows), y is "vertical" (columns).

Because of the way the loop works, x then y makes columns. So the first loop, x=0, runs the y loop - 0,0 | 0,1 | 0,2 | 0,3| ... | 0,7 - after completing, the next x loop runs 1,0 | 1,1 | ... and so on.

Basically when you have y as a subevent of x, each entire y loop has to finish per loopindex of x. When you take the x loopindex as the y coordinate and vice versa, the position in which they get placed gets inverted as well.
B
58
S
29
G
119
Posts: 1,783
Reputation: 67,443

### » Thu Apr 27, 2017 10:02 pm

@newt
Are you sure you are running the layouts in the order you think you are? (I always forget to select the layout I want when testing).

it works the way I would expect. There are two loops - an inner and outer loop. The inner loop "y" runs 9 times for each of the outer loop "x" cycles.
when you create the sprite object, you will get either rows or columns depending on which order you put the loopindex variables in the create object.

The first layout gives me rows the way I would expect, because the first coordinate given is the Y loopindex.
The second layout makes columns because the inner loop is now in second coordinate...
B
99
S
35
G
20
Posts: 438
Reputation: 17,950

### » Thu Apr 27, 2017 10:14 pm

I expect
for x= 0 to 3
->for y= 0 to 3, create object at x component= loopindex(" x"), y component= loopindex("y")
To give me:
0,1,2,3
4,5,6,7
8,9,10,11
12,13,14,15
B
175
S
50
G
199
Posts: 8,625
Reputation: 124,026

### » Thu Apr 27, 2017 10:29 pm

Don't think it ever worked like that. Since X is the parent loop, the order will be

0,0
0,1
0,2
0,3
1,0
1,1
1,2
1,3

and so on.

Just swap x and y in the conditions. Also it doesn't need to be in a subevent btw, the two loops can go in the same event.
B
58
S
29
G
119
Posts: 1,783
Reputation: 67,443

### » Thu Apr 27, 2017 11:48 pm

@newt nope, that what i was thinking also but is as oosyrag says well kinda...

its like this if i remember properly.... no matter which way it is... for u to get

1234
5678

you need to make a loopindex(x)*10 / by something forgot the formula and then u get it one after each other. il be back with it.

0000000000000000000000000
1
2
3
4
5
6
7
8
9
B
82
S
24
G
69
Posts: 1,362
Reputation: 44,214

Next