Making a family based event only affect an individual

This forum is currently in read-only mode.
From the Asset Store
Very simple code without excess options (15 events for server and 11 events for client)
  • I want a laser blast to hit a someone from the family "Enemies" and give a set number of damage. I want multiple enemies on the screen at once as well. The reason being so that I can set varied levels of health for different types of enemies, and additionally set different kind of damage dealt by projectiles of varying sorts (when I add more; for instance a laser might do 2 damage, while a bullet does 5).

    When I implement this, however, as soon as the laser hits the person from the "Enemies" family, everyone in the "enemies" family destroys... which I don't want to happen. I just want it to affect individual enemy units. I understand how to do this with private variables. I'm not sure if I should redefine all of my family variables or what.

    Setting all enemies into a family would prevent me from defining EVERY event for all of my enemies in the event that I would have to use object specific private variables. I'm new to this, so I apologize if I'm wasting space with newb questions.

  • REVISION!!!

    After playing around with it, I had to remove the entire "Enemies" family first, remove the private variables that were still assigned to the bad guy in question, re-add the family and the family variables and re-assign that family to the bad guy.

    This made them act individually. For my case, each could take two hits before destroying itself.

    SO HERE IS MY NEXT QUESTION! Is it possible to have a private variable for an object that is still in a family? I know the entire point of a family is to share variables, but a few variables I need individualized on a per object basis.

    What I want to do is assign levels of health (HP) to different objects. When someone from family "enemies" is hit by a projectile (which has variable "Damage_dealt" set to 2), it will calculate HP-damage_dealt. When HP=0, it would then go back and destroy the object from the "enemy" family. Is this possible, or is it a no-go from the individualized private variables, yet still in the family issue?

    I guess what I want to do is modularize EVERYTHING, so I can throw in a new enemy, set it to family enemy, set how much health it has, and be good to go.

    Is there a way to have Family Private Variables while at the same time having Object Private Variables?

    One idea I was throwing around to see if it was viable, was to remove the bad guy from the "Enemies" family to give me individualized private variables again, create an invisible, essentially hit box, and assign THAT to the "enemies" family. Then I would make that box in the same container as the bad guy and tell it to always use the same position as the bad guy sprite so it would follow it around. When that box collides with a projectile, it takes the bad guys's HP variable and subtracts the "damage_dealt" variable. When HP=0 it's destroyed.

    Would that work, or would that just destroy all enemies once the condition for destroying is met?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Alright, well, sorry for the quadruple post, this is the last one I swear, but I went ahead and tried my idea above, and it just didn't work since I apparently overlooked the concept that private variables are highly object specific.

    So I either need a way to give private variables to objects already in a family, OR a way to link various object variables to specific objects so that their private variables can be called up.

    Maybe the addition of a checkbox in the Private Variable section to say whether a partcular private variable is assigned to the rest of the family IF AND ONLY IF that variable is different from the list of variables in the Manage Families window, for a specific family?

    Thoughts? Is there a more efficient/better/actual way to do this? It would make my life infinitely easier especially since I want to add 4+ different types of projectiles, along with a whole slew of different kinds of enemies.

  • Family object picking works like normal object picking: if you have

    + Family Red 'Health' less or equal 0

    -> Destroy Family Red

    then only objects from the family Red with 'Health' <= 0 get destroyed. They shouldn't all be indiscriminately destroyed. If they are, it might be a bug, so upload a .cap showing this behaviour and I'll take a look.

    The way family private variables work is like this. Suppose you have 'SpriteA' and 'SpriteB' in family 'Red'. The private variables available in Red are the ones common to both SpriteA and SpriteB. So if you have:

    SpriteA's variables: VarA, VarB, VarC

    SpriteB's variables: VarA, VarB

    then via the family Red, you can access VarA and VarB, because all objects in the family have them. You can't access VarC: if you did 'Set VarC to 5', SpriteB doesn't have a VarC, so it's impossible to carry out this action. However, in ordinary non-family events referring to SpriteA, you can still use VarC like a normal private variable.

    The Family Manager dialog allows you to add and remove private variables to all the objects in the family at the same time. If you have 17 objects in family Red and you want to have a new variable 'VarD', you don't want to have to add 'VarD' individually to 17 objects. So you just hit 'Add new family variable' and add 'VarD', and it adds it to all of them. Because all of them have the variable in common, it becomes a family variable.

    I should note families keep a separate record of which objects are picked in the events. So if you have:

    + Bullet collides with family 'Red'

    -> Destroy SpriteA (which is in family 'Red')

    then this event treats SpriteA as unpicked by the event, so all SpriteAs will be destroyed. If you want to use only the objects affected by the event, choose an action under the 'Red' family in the event wizard (eg. Family 'Red': Destroy).

    Hope that explains it!

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