Order of operations for loops

0 favourites
  • 12 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Check the active event sheet for each layout.... We've all been there!

  • 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.

  • 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...

  • I've updated the capx to illustrate the difference with some text.

  • 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.

  • 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...

  • 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

  • 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.

  • 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.

    edited: i know is been 2 years sorry for bringing it up, but the math i was talking about was

    loopindex("x") +loopindex("y") * number of loops for each for example

    if you have a

    for "x"

    from 0 to 4 (which is 5 including 0)

    for "y"

    from 0 to 4

    we then get the value bellow

    5 = x.N_horizontal_loops = number of loops on the horizontal lines counting 0 as 1 (so 0 to 4 =5 0 to 11 = 12, this works even if you have loopindex y loops greater than nr of loops of x)

    and you will get the following order

    0,1,2,3,4

    5,6,7,8,9

    10,11,12,13,14

    15,16,17,18,19

    20,21,22,23,24

  • Alright, I guess I got it backwards.

    The x component for the first loop would be 0.

    That's not a row.

    Thanks to all that took a look.

  • yeah it depends on how you look at it but for me X is always the row and Y is the columns... I hate the way C2 says X is the width.. and Y is the height.. it's completely wrong to me. Height should be the number of rows or "records" and width should be the columns or fields

    FRED SMITH 12 LANDAU LANE

    BOB SMITH 21 MAIN STREET

    JANE DOE 19 FREE STREET

    not

    FRED SMITH BOB SMITH JANE DONE

    12 LANDAU LANE 21 MAIN STREET 19 FREE STREET

    that's more like the way it is shown here:

    https://www.scirra.com/tutorials/307/ar ... ers/page-4

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)