Families, targeting objects variable

Get help using Construct 2

Post » Fri Apr 13, 2012 5:23 pm

I cant seem to figure out how to target the variables of the objects in a family, it seems the only way to do so is to apply the variables to the family instead, in other words, if i wanted to have object 1 have a health of 10, and object 2 to have a health of 100,
if i want to say if ( family
) health da da da, it is not impossible, is there anyway to do this?
the family should target the objects variables in side of it FFS
not apply variables to the familiy, what if i want the objects to have different stats? -.-

B
9
S
4
G
3
Posts: 223
Reputation: 3,433

Post » Fri Apr 13, 2012 5:52 pm

so its impossible then -.-   thats pretty lame
B
9
S
4
G
3
Posts: 223
Reputation: 3,433

Post » Fri Apr 13, 2012 6:03 pm

Do you have a CapX that shows your problem so we can help you work thorough it? You can change a single variable on an object if you program the events correctly... (Even using families...)
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Mon Apr 16, 2012 5:44 pm

so you can change the variable of an object through a family event?

so if hit family, check variable for object inside family?
B
9
S
4
G
3
Posts: 223
Reputation: 3,433

Post » Mon Apr 16, 2012 6:18 pm

Show us your capx file so we can help you break it down.
B
20
S
5
G
5
Posts: 66
Reputation: 4,515

Post » Mon Apr 16, 2012 7:05 pm

If you have to separate objects and give each a variable "health" then add both objects to a family then you can't access "family.health".

Instead add both objects to a family and add a family variable "health" and then the objects will inherit "health" variables, then you can access "family.health".

Does this help? If not a capx would help immensely.
B
79
S
24
G
54
Posts: 4,746
Reputation: 40,755

Post » Wed Apr 18, 2012 5:24 pm

so every object in the family would have a health of 0, if i wanted different things to have a different health i would have to on spawn tell them to change their health ?
B
9
S
4
G
3
Posts: 223
Reputation: 3,433

Post » Wed Apr 18, 2012 10:02 pm

You can set the default health to 0 but if you place a few objects in the layout you can change each object's variables to something different than each other. If you spawn an object via events, you just need to place an action in the same event block telling the object to set its health and it should only pick that freshly spawned object and not effect the others in the family.
B
58
S
20
G
7
Posts: 305
Reputation: 8,804

Post » Thu Apr 19, 2012 7:42 am

I'm having the same problem as cs2curious.
If we just go by the family example that comes with cs2, how would we give each of the 7 different enemies their own health value? If all code is being told is that the laser has collided with "a member of the 'Enemies' family", I want to say "-100 from it's health" but have the starting healths all different. I'm thinking it should be something like "-100 to [family].member.'health'"?
So far I've just copied and pasted a heap of times but if I can find out how to do this it would save heaps of work.
B
21
S
7
G
3
Posts: 33
Reputation: 4,522

Post » Thu Apr 19, 2012 12:40 pm

A Simple way to use families:
1. Add your sprites to the game (say all your "Enemy" sprites)
2. Create a Family called "Enemy Family"
3. Add all the enemy sprites to this Family
<Key Part below>

4. Add instance variables to your Family. Each variable will now become available to the individual members in the family

5. In C2, you need to have at least one instance on the layout (maybe outside the view) to be able to create them on runtime. Make sure you have at least one instance of each of the Enemies created on the layout

6. Edit the inherited instance variables of individual members in the Enemy Family. You will notice that each member retains the value set to its instance variable.

Eg: 'Health' is a Family variable. 'Health' for EnemyMemberA can be 100 and for EnemyMemberB can be 200.

Even when you spawn individual Family Members at runtime, they will get created with the initial set of individual values for the instance variable.

Hope this helps.
B
27
S
6
G
6
Posts: 20
Reputation: 6,132

Next

Return to How do I....?

Who is online

Users browsing this forum: armaldio, blackhornet, makkancs, TiagoCesar and 17 guests