Family instance variables question

  • I'm trying to give different IDs to each instance of a family.

    Suppose I have a family called Units that contains several different sprites. The family has a family instance variable called ID that starts at 0.

    Each time I spawn a sprite, I set its ID to Units.ID + 1. Suppose I spawn 3 sprites - will the sprites have IDs of 1, 2, 3?

    Just trying to figure out how to give different ID values to instances of a family.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi Excal

    If the family instance variable has a default value of 0.

    And when you add a new sprite you set it to Units.ID(the default value) + 1

    The new sprite's ID will be the default value + 1.

    So in the mentioned case all your sprites IDs would be 1.

    If you want different IDs for each you have to make a global variable which tracks the number of spawned sprites.

  • Turns out I was being stupid and just needed to use UID ;)

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