Do Multiple Actions in Repeat Loop?

  • I'm trying generate the above grid of objects dynamically (I want to be able to fade in each cell separately). The method I started using is

    System | for 1 to 5 > create-object "hex_slot" on layer "slots", x: hex_slot.X + (loopindex*150), y: hex_slot.Y

    This allows me to generate the first row. But each instance created has an opacity of 100, so I need to change the opacity of each instance to 0. Or say I want to set an instance variable value of the instance. Would I do this after each instance is created, or use a completely separate repeat loop that runs through all the created instances?

    Also, how do I increment the Y position value to generate the next rows of cells? Typically to build a grid I would use a nested repeat loop, something like this (pseudo code):

    X = 0, Y = 0

    repeat with v = 0 to 5

       repeat with h = 0 to 5

          create object at X+(h*40), Y+(v*40)

       end repeat

    end repeat

    How is this done in Construct, or is a different method needed?

  • You can change opacity or set instance variables immediately after the "Create" action.

    Instead of "Repeat" use "For" loop and loopindex() expression:

    For "y"=1 to 6

    ...For "x"=1 to 6

    ........create object at (loopindex("x")*40), Y+(loopindex("y")*40)

    ........Object set opacity to 0

    Loopindex (without parameters) works with "Repeat" loops too, but if you have two nested Repeat loops, you can't reference both of them.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you. I was wondering how to physically nest the statements and it took several attempts at dragging the lines in the editor to get them to orient properly. And now I realize that loop names can be variables [forehead slap].

    Aside from the numeric values, does this arrangement look correct?

  • Yep, everything looks perfect.

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