Order of operations for loops

Discussion and feedback on Construct 2

Post » 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.
Image ImageImage
B
169
S
50
G
173
Posts: 8,321
Reputation: 110,286

Post » Thu Apr 27, 2017 7:59 pm

Check the active event sheet for each layout.... We've all been there!
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Thu Apr 27, 2017 8:28 pm

I just haddn't linked the sheet for the first save.
Sorry, it should be correct now, otherwise just link 1 to 1, 2 to 2.

Still sure something's changed with loops however.
Image ImageImage
B
169
S
50
G
173
Posts: 8,321
Reputation: 110,286

Post » 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...
A big fan of JavaScript.
B
74
S
20
G
71
Posts: 2,228
Reputation: 44,888

Post » Thu Apr 27, 2017 9:02 pm

I've updated the capx to illustrate the difference with some text.
Image ImageImage
B
169
S
50
G
173
Posts: 8,321
Reputation: 110,286

Post » 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.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,609
Reputation: 61,639

Post » 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
96
S
33
G
20
Posts: 438
Reputation: 17,665

Post » 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
Image ImageImage
B
169
S
50
G
173
Posts: 8,321
Reputation: 110,286

Post » 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.
Mistakes were made.
B
52
S
26
G
109
Posts: 1,609
Reputation: 61,639

Post » 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
77
S
23
G
69
Posts: 1,353
Reputation: 43,958

Next

Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 7 guests