Instance variables for objects in a family

Get help using Construct 2

Post » Sat Feb 02, 2013 2:19 am

Hello,

This seems basic to me, but I haven't been able to find the answer in the manual, tutorials, or forum, so here goes.

I am doing my own version of the "ghost shooter" game from the beginner tutorial. I would like to have multiple types of enemy, each with their own health pool (some higher, some lower).

I want to take advantage of families so that I don't have to re-create the events dealing with enemy collisions or enemy death. However, on collision with the good guy's weapon, I need to decrease the particular enemy's health by one.

So, I could use instance variables specific to each enemy, but then I can't access it through the family. I could set a family instance variable and let it be inherited by the objects in the family, however that would effectively set them all to the same health.

What I'm looking for is a way to drill down to the particular object instance within a family that triggered the event and access its instance variables. Any ideas?

Thanks!!


B
3
Posts: 7
Reputation: 289

Post » Sat Feb 02, 2013 2:26 am

Hello Sir !

I just want to say that you should use families for the general events ( Like the Death-Related animations or stuff like that ) and you should use enemies instance variables to give them life meters damage meters

...

Cheers !

P.S. : I don't know if that answered your question or not , If it didn't please explain with cases or examples and include @Whiteclaws in your post !
B
35
S
16
G
16
Posts: 2,222
Reputation: 16,589

Post » Sat Feb 02, 2013 6:45 pm

Just to expand on what Whiteclaws is saying...

I still have the free version of C2 at the moment so I haven't used families yet and can't verify what I'm about to claim...
but I think you can use a family instance variable for health and just set the value of the variable for each object (enemy) in the family.BenGIJOE2013-02-02 18:46:20
B
5
S
1
G
1
Posts: 12
Reputation: 899

Post » Sat Feb 02, 2013 7:21 pm

[QUOTE=jmay1982]
So, I could use instance variables specific to each enemy, but then I can't access it through the family. I could set a family instance variable and let it be inherited by the objects in the family, however that would effectively set them all to the same health.

[/QUOTE]

You can actually do this.

Create a family, add objects and shared variables into it. Now go look into objects variables in the editor and you'll see the family's variables in the objects properties. You can set them into whatever you desire, so different enemies can have different health by default. :)
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Sun Feb 03, 2013 6:07 pm

[QUOTE=vee41] [QUOTE=jmay1982]
So, I could use instance variables specific to each enemy, but then I can't access it through the family. I could set a family instance variable and let it be inherited by the objects in the family, however that would effectively set them all to the same health.

[/QUOTE]

You can actually do this.

Create a family, add objects and shared variables into it. Now go look into objects variables in the editor and you'll see the family's variables in the objects properties. You can set them into whatever you desire, so different enemies can have different health by default. :)[/QUOTE]

AHA!

I had actually tried this before posting, however I was looking at the instance variables for the object, not in the properties panel.

So now my event looks like:
Bullet on collision with BadGuy: Subtract 1 from BadGuy health.

Now that I can set the health for each type of bad guy independently, this works out perfectly.

Thanks!
B
3
Posts: 7
Reputation: 289


Return to How do I....?

Who is online

Users browsing this forum: WhosWho and 14 guests