How do I get the child's instance variable inside families

0 favourites
  • 13 posts
From the Asset Store
A collection of various zombie characters sprites for creating a 2D platformer or sidescroller game
  • Example:

    Player hit objects in families.

    I want to decrease the health of that object.

    How Can I do?

  • Construct2's typecasting

    + Player: on collide with familyObject
    + SpecificObject: UID = familyObject.UID
             -> SpecificObject: substract 1 from hp[/code:1zsh9bm6]
  • Yann Typecasting ? Thanks for this one, I was still calling a custom function with familyObject.UID, and then selecting the specificObject by its UID in the function.

    PS : As I didn't understand right away, I made it as an example in attachment.

    Blue and Black are in the family "movable", Red is not.

    Blue has a "speed" variable, and black has "hp". On collision, depending on the object colliding, the corresponding action will be called.

  • Guizmus yes, typecasting

  • Um you shouldn't need to pick via uid, families do all that for you.

    All you have to do is subtract from the family, as the particular object is already picked.

    Just make sure the variable belongs to that family.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • newt you do need to pick via UID if you want to know what is the particular object type of the family member you picked (yes it's usefull sometimes)

    However, I agree with you on the fact that if he wants to decrease the hp of any object in the family, the hp should be a family variable, not an instance variable.

  • Actually I would probably go with an instance variable there since picking by uid is limited to a specific instance.

    That is unless you really have to pick outside of that event, like a function.

  • newt using an instance variable would be redundant in this case.

  • Um you shouldn't need to pick via uid, families do all that for you.

    All you have to do is subtract from the family, as the particular object is already picked.

    Just make sure the variable belongs to that family.

    OK. I know this is over 2 years later, my apologies. But how did you get a Family Instance Variable with the same name as a Object Instance Variable??

  • You don't.

    If you use the object in the condition, then you use the object's instance variable.

    If you use the family in the condition, then you use the family variable.

    If you want to pass a value to an entire family, or all instances in the same event, you have to go outside picking.

    A function works well for that.

  • In your capx though, you have given the Family an Instance Variable of "HP", and both objects within the Family each have an "HP" instance variable..?

  • O jeesh... nevermind.

    "If you add an instance variable to a family, all the object types in the family inherit the instance variable."

  • It picks both variables, family, and instance, even though only the family is referenced.

    That's what you call an undocumented "feature".

    I wouldn't rely on it.

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