Instance variables for objects in a family

0 favourites
  • 5 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • Hello,

    This seems basic to me, but I haven't been able to find the answer in the manual, tutorials, or forum, so here goes.

    I am doing my own version of the "ghost shooter" game from the beginner tutorial. I would like to have multiple types of enemy, each with their own health pool (some higher, some lower).

    I want to take advantage of families so that I don't have to re-create the events dealing with enemy collisions or enemy death. However, on collision with the good guy's weapon, I need to decrease the particular enemy's health by one.

    So, I could use instance variables specific to each enemy, but then I can't access it through the family. I could set a family instance variable and let it be inherited by the objects in the family, however that would effectively set them all to the same health.

    What I'm looking for is a way to drill down to the particular object instance within a family that triggered the event and access its instance variables. Any ideas?

    Thanks!!

  • Hello Sir !

    I just want to say that you should use families for the general events ( Like the Death-Related animations or stuff like that ) and you should use enemies instance variables to give them life meters damage meters

    ...

    Cheers !

    P.S. : I don't know if that answered your question or not , If it didn't please explain with cases or examples and include Whiteclaws in your post !

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Just to expand on what Whiteclaws is saying...

    I still have the free version of C2 at the moment so I haven't used families yet and can't verify what I'm about to claim...

    but I think you can use a family instance variable for health and just set the value of the variable for each object (enemy) in the family.

  • So, I could use instance variables specific to each enemy, but then I can't access it through the family. I could set a family instance variable and let it be inherited by the objects in the family, however that would effectively set them all to the same health.

    You can actually do this.

    Create a family, add objects and shared variables into it. Now go look into objects variables in the editor and you'll see the family's variables in the objects properties. You can set them into whatever you desire, so different enemies can have different health by default. :)

  • >

    > So, I could use instance variables specific to each enemy, but then I can't access it through the family. I could set a family instance variable and let it be inherited by the objects in the family, however that would effectively set them all to the same health.

    >

    >

    You can actually do this.

    Create a family, add objects and shared variables into it. Now go look into objects variables in the editor and you'll see the family's variables in the objects properties. You can set them into whatever you desire, so different enemies can have different health by default. :)

    AHA!

    I had actually tried this before posting, however I was looking at the instance variables for the object, not in the properties panel.

    So now my event looks like:

    Bullet on collision with BadGuy: Subtract 1 from BadGuy health.

    Now that I can set the health for each type of bad guy independently, this works out perfectly.

    Thanks!

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