0 Favourites

families and variables

  • So i have a little problem. I want to deal damage to my enemies and i dont know how would i do it.(I know how but only if i code for every enemy and every weapon) Could i do something like:

    Family(enemies) > on collision with sword

    subtract from....

    and that is what bothers, should i have a global variable, or instance variable, and do i have to do it for each enemy or can i do it for whole family?

    Thanks in advance.

  • You can't use families with the free version of C2

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • i dont have a free version

  • i have the educational or whatever its called licence

  • Think of the family itself as a parent object with a hierarchy that extends down to all its children. The family contains the behaviours, the variables and the effects, and every child within the family receives those properties. On top of that, you can specify new values for the children.

    So, assume you have the family Enemies, and inside it are Goblin, Orc and Skeleton. The family is given the HitPoints variable with a default value of 10. Every instance of each child in the family will be given that value by default, but you can override those defaults either at runtime (with events) or at design time in the layout editor. So the Goblin keeps the default HitPoints of 10, but you can tell the Orcs to have 20 HitPoints and so on.

    When it comes to picking those children in events, you refer to the entire family as a sort-of blanket condition. If sword hits Enemies, do this and that. This will check to see if the sword hits any of the family members. What happens here is pretty cool: once the condition is met, C2 remembers exactly which instance of which child is hit, and will use that instance for the rest of the event's actions. So when you then go on to say Subtract 10 HitPoints from Enemies, it will only subtract from that specific enemy.

  • Just tried it out and works perfectly, thanks man.

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
64 12,940
trollface's avatar
trollface
Unread hot topic
52 3,006
Ashley's avatar
Ashley Construct Team Founder
Unread hot topic
44 14,822
R0J0hound's avatar
R0J0hound