0 Favourites

Order of operations for loops

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

  • 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

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • 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.

    0000000000000000000000000

    1

    2

    3

    4

    5

    6

    7

    8

    9

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