Is there a way to use object variables within families?

0 favourites
  • 4 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I'm aware that I can add variables to families but I don't think I can achieve what I want using that method?

    What I'm trying to achieve: I have lets say 5 enemies and 5 friendlies that have their own health and damage.

    I want to just group all the enemies together and friendlies separately in their own families while having one line of code that deals damage to each other.

    For example 1 enemy might have 100hp and 20 damage while another enemy has 150hp and 40 damage when attacking a friendly. Is there a way to do this using families?

    Thank you for your time.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Objects can be in multiple families. If there are any variables that apply to both enemies and friendlies - you can define them on AllEntities family, which contains all objects.

    You will be able to do damage to both with a single line of code:

    AllEntities subtract 1 from HP

    But these variables will not be available in Enemies and Friendlies families. So you can do this:

    Skeleton subtract 1 from HP

    But not this:

    Enemies subtract 1 from HP

  • The problem is; if I add a variable to a family then all objects within the family share the same value?

    For example enemyA and enemyB would have the same health and damage

  • For example enemyA and enemyB would have the same health and damage

    Not necessarily. The way it's usually done is you add a repository layout where you put one instance of each object - it will be the default instance. Every new instance you create in the editor or in runtime will be copied from that default instance.

    So you can place all enemies and friendlies on that repository layout and configure different hp/damage values for them.

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