How do I Spawn a particular object member of a family

Get help using Construct 2

Post » Sun Oct 04, 2015 9:44 pm

Hello guys,
First of all, sorry about my english. I know it's very poor but i hope that you can understand my problem.
Well, i'm actually working on a RPG project, but it's a little bit different from the usual, like action RPG or JRPG.
So i'm thinking to use a lot of enemies with different sprites and stats, so i chose to use the "family" function, because using the family function i can create instances/variables for all my enemies, for example: Name, Strenght, Defense, Magic Attack, HP... And all of these variables are linked to enemy objects.
Now i'm trying to "spawn" a particular enemy from this family, however i don't know how to do this action... Is there any way to do this? For example:

Family: Enemies
Member: 1) Zombie
Member: 2) Ghost
Member: 3) Wolf

And i want to spawn a Ghost using the family's instances.
How can i do this?
When i try to summon an enemy the result is always random.
Thank you.
Danilo.
B
3
Posts: 1
Reputation: 177

Post » Sun Oct 04, 2015 10:54 pm

You can just create the Ghost object, and the newly created object will be part of the Enemy family.
B
47
S
22
G
65
Posts: 1,127
Reputation: 38,395

Post » Sun Oct 04, 2015 11:06 pm

daniloaguiarb wrote:Hello guys,
First of all, sorry about my english. I know it's very poor but i hope that you can understand my problem.
Well, i'm actually working on a RPG project, but it's a little bit different from the usual, like action RPG or JRPG.
So i'm thinking to use a lot of enemies with different sprites and stats, so i chose to use the "family" function, because using the family function i can create instances/variables for all my enemies, for example: Name, Strenght, Defense, Magic Attack, HP... And all of these variables are linked to enemy objects.
Now i'm trying to "spawn" a particular enemy from this family, however i don't know how to do this action... Is there any way to do this? For example:

Family: Enemies
Member: 1) Zombie
Member: 2) Ghost
Member: 3) Wolf

And i want to spawn a Ghost using the family's instances.
How can i do this?
When i try to summon an enemy the result is always random.
Thank you.
Danilo.

You have two options to do this. First one is a plugin (as far as I remember) that allow you to do this. However can't remember the name, but maybe someone can?

The other one which is the one I normally use, is to simply spawn the object that you added to the family. For instant:

Code: Select all
Object Zombie
Object Ghost

Both of these are in the family Enemy


These object have the same UID whether you refer to them through the family or as individually objects. So you can select them both using the same UID, which also means that you can spawn an individual object and still select it through the family. However you still have to respect the picking rules which are very important or you will run into problems. But to explain them, as they are fairly simple:

Code: Select all
Create Zombie
--> Enemy.HP = 100
//This is not valid even though Zombie is part of family Enemy it is still a Zombie object. So in this case you would set all Enemy.HP = 100. So you always have to distinguish between Family objects and individual objects.

Create Zombie
--> Zombie.HP = 100
//This is the correct way to do it. As you create the Zombie you automatically pick it. So setting Zombie.HP = 100 will only set it for this Zombie object.


Since Zombie is still part of the family, you can still "convert" a pick of a zombie into a Family pick, or what to call it. Which you can do like this:

Code: Select all
Pick Zombie.HP = 100
For each Zombie
Pick Enemy.UiD = Zombie.UID
<Do something>

//Since you start by picking all zombie which have 100 HP, you can pick the corresponding Family object by throwing in a For each and then pick the Enemy.UID = Zombie.UID as these are shared.


Hope that helps.
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests