families and variables

Get help using Construct 2

Post » Sun Mar 02, 2014 4:36 pm

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.
B
7
S
2
Posts: 102
Reputation: 975

Post » Sun Mar 02, 2014 4:52 pm

You can't use families with the free version of C2
I will not let you reach the sisters
Nature Forums
B
11
S
5
G
2
Posts: 496
Reputation: 2,306

Post » Sun Mar 02, 2014 4:55 pm

i dont have a free version
B
7
S
2
Posts: 102
Reputation: 975

Post » Sun Mar 02, 2014 4:56 pm

i have the educational or whatever its called licence
B
7
S
2
Posts: 102
Reputation: 975

Post » Sun Mar 02, 2014 4:58 pm

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.
B
57
S
15
G
11
Posts: 912
Reputation: 12,606

Post » Sun Mar 02, 2014 5:08 pm

Just tried it out and works perfectly, thanks man.
B
7
S
2
Posts: 102
Reputation: 975


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 9 guests