0 Favourites

Families and Objects' private instance variable

  • Hello everyone!

    I read this two pages froms Scirra's site

    Families

    Beginners Guide - P6

    And I'm trying to merge the two tips.

    My goal: I'd like to have enemies with different life points but manage the life points subraction with the families system (just to avoid writing the same line so many times as the number of enemies).

    I'm facing this issue:

    => if I use a family Instance Variable, the value for each enemy can't be different as it could be with private instance variables.

    => if I don't use family Instance Variable, I cannot access the Object instance variable while I'm verifying the collision of a bullet, for example, with the "enemies" family. I can only verify the collision and destroy th Object (as shown in the manual). But If I just want to subtract some life for each collided bullet?

    Can someone help me, please?

    I couldn't find any answer in Scirra's pages.

    Thank you in advance

  • => if I use a family Instance Variable, the value for each enemy can't be different as it could be with private instance variables.

    It can be. You can do

    +Bullet: On collision with Enemies
       -> Enemies: Subtract 1 from Health
    
    +Enemies: Health = 0
       -> Enemies: Destroy
    

    where 'Enemies' is a family.

  • >

    > => if I use a family Instance Variable, the value for each enemy can't be different as it could be with private instance variables.

    >

    It can be. You can do

    > +Bullet: On collision with Enemies
       -> Enemies: Subtract 1 from Health
    
    +Enemies: Health = 0
       -> Enemies: Destroy
    

    where 'Enemies' is a family.

    Also, when you use an instance variable for the family, it only have the purpose to make easy your job by sharing the same instance name with all the objects inside, but each individual instance of the family will manage their instance variables individually (or not, if you set to all of them change the variable)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Thanks to ramones and TELLES0808 for your replies.

    In the way you suggested me it seems I have to set the value Health for each enemy everytime it's spawned, because it cannot be assigned a priori.

    I would have liked that families' IV overrided the single object's IV so I could declare private IV this way:

    enemy -> health = 1

    bad_enemy -> health = 3

    verybad_enemy -> health = 5

    motherf####r_enemy -> health = 10

    boss -> health = 50

    and then apply a rule like

    +Bullet: On collision with Enemies

       -> Enemies: Subtract 1 from Health

    +Enemies: Health = 0

       -> Enemies: Destroy

    But I understood it's not so... <img src="smileys/smiley19.gif" border="0" align="middle" />

    Now, if I declare a family's IV Health = X, X will be the value for every health of every enemy. For sure indipendent for each enemy, but with the same start value and this is what I would like to avoid: the same start value for each enemy.

    I suppose I can make a workaround assigning the Health value after spawning the enemy, but it's not an elegant solution: it's hardcoded and I prefer to modify a parameter of an object rather than a code line, if I want to make a change.

    Any suggestion?

    Or my workaround is the only way?

    Thank you all in advance

  • You also have to set family variable for enemies names. So you can set ie. family.name = set family.health

    Family.enemy - Set Family.health to 1

    Family.bad_enemy -> Family.health = 3

    Family.verybad_enemy -> Family.health = 5

    Family.motherf####r_enemy -> Family.health = 10

    Family.boss -> Family.health = 50

  • Now, if I declare a family's IV Health = X, X will be the value for every health of every enemy. For sure indipendent for each enemy, but with the same start value and this is what I would like to avoid: the same start value for each enemy.

    If you click on the family and change the health variable it will apply to all enemies in the family. But you can select the boss sprite and change it's health to 50 without affecting the other enemies.

  • Thank you all!! <img src="smileys/smiley32.gif" border="0" align="middle" />

    Sorry if I wastred some of your game-developing time <img src="smileys/smiley2.gif" border="0" align="middle" />

    @ramones it was very simple but I was a little bit blind..

    I was looking for something ignoring the things before my eyes <img src="smileys/smiley18.gif" border="0" align="middle" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread hot topic
0 Favourites
[Plugin] instance bank2
85 18,367
rexrainbow's avatar
rexrainbow
Unread hot topic
64 12,940
trollface's avatar
trollface
Unread hot topic
52 3,004
Ashley's avatar
Ashley Construct Team Founder