How do I work with one instance at a time and its children with a For Each loop?

0 favourites
  • 4 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies. For use in game and custom works.
  • I have a For Each loop where I'm picking every instance of a family, programmatically adding a sprite font named ButtonText as a child to the Buttons and setting some properties on the ButtonText based on properties of the button parent.

    The problem is that when setting those properties, it sets the properties for ALL ButtonText instances, using the properties of the FIRST Button, instead of using the values of the instance being looped over and setting the properties of the child of that instance.


  • in event 7, where you add child ButtonText, you are not picking one instance of ButtonText so ALL instances are being added as a child to Button, and then they are all getting the same properties.

    If Button was a container, then each Button would have its own instance of ButtonText (but families can't be a container). So, you can create an instance of ButtonText for each Button, or if they are already on the Layout, pick the nearest instance or use some other way to associate a ButtonText with the appropriate Button (and pick just that one instance).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • in event 7, where you add child ButtonText, you are not picking one instance of ButtonText

    Shouldn't the Loop pick instances as they are being looped over?

    Here is the result, as you can see the ButtonTexts are being placed correctly but their text, width and height is all taken from Button #0 there at the bottom.

  • Yes, that's exactly what it does - it picks your button instances one by one. But that has nothing to do with your button text. Construct doesn't know which text belongs to which button and because you aren't picking any specified button texts in your loop event it simply adds all texts as a child at once.

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