nested loop for each sprite instances

0 favourites
  • 3 posts
From the Asset Store
For Adventure, Action, Heroes, Sci-fi and Action-RPG games.
  • Is it possible to use For each loops to iterate over nested loops in the following way?

    For Each Sprite: set i to sprite.UID

    For each Sprite: set j to Sprite.UID

    Array set at XY(ii, jj) = some number

    Looking at the debugger, it seems that the first loop iterates entirely, then the next loop; in other words, they are not treated as nested like it would in a typical programming context. This example is trivial, but I am wondering if/how this works in Construct generally. Can anyone help and/or explain?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is it possible to use For each loops to iterate over nested.

    My guess, it's not possible with 'For each', because the first 'For each' picks a sprite and for the second 'For each' there is only this sprite visible.

    But it should work with a normal 'For loop'. You can address a sprite directly with Sprite(IID).

    It would look for example like this:

    + System: For "loop1" from 0 to Sprite.Count-1

    ----+ System: For "loop2" from 0 to Sprite.Count-1

    -----> Text: Append Sprite(Loopindex("loop1")).UID & " "&Sprite(Loopindex("loop2")).UID & newline

    This puts two UIDs from the sprites in a line in a Textbox. With loopindex("name of loop") you get access to the currently loopindex of this loop.

  • Perfect, that's what I was looking for.

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