How do I create objects with respect to family inst.variab.?

Get help using Construct 2

Post » Thu Mar 20, 2014 2:51 pm

Hello everyone,

I want the system to create an object of a family with a certain family instance variable. I`ll give you an example:

-There is a family called "Enemies" and the family instance variable "Enemy_type"
-There are two Enemies: Enemy1 with Enemy_type=1 and Enemy2 with Enemy_type=2, both are part of the family "Enemies"
-I want to achieve something like this: System: Every 5 seconds -> Create Object "Enemies", for which Enemies.Enemy_type=2

That means that every 5 seconds, Enemy2 will be spawned while Enemy1 will not be spawned. This is very useful for having influence on randomized spawns (in my game at last). I tried something like "If Enemy.Enemy_type=2 -> Create Object Enemies", but this doesn`t work, because every enemy can be created.

Maybe someone has an idea on how to solve this? Thanks in advance!
CreativeMind
B
17
S
7
G
2
Posts: 110
Reputation: 2,665

Post » Thu Mar 20, 2014 3:40 pm

You just create Enemy2 and set it's Enemy_type to2.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Sat Mar 22, 2014 2:04 am

Obviously I failed in describing my problem clearly :D Thanks for the answer, I`ll try to point out what I mean in a more understandable way:

I want the system to check first which family-instance has the family instance variable =2, and then spawn only those enemies for which the variable is =2. I`ll give you another example:

There are three enemies: Bug-enemy, robot-enemy and weirdo-enemy. I want them to spawn randomly. I could use a code like this, which is very inefficient:

System: Every 5 seconds -> Set randomnumber=choose(1,2,3)
If randomnumber=1-> Spawn bug-enemy
If randomnumber=2-> Spawn robot-enemy
If randomnumber=3-> Spawn weirdo-enemy

This code is very inefficient. I want to use a more elegant way by creating a family called "Enemies" and the family instance variable "Enemy_ID". The values of this family instance variable are 1 for the bug-, 2 for the robot- and 3 for the weirdo-enemy. I want the code to look something like this:

System: Every 5 seconds -> set randomnumber=choose(1,2,3)
If randomnumber=Enemies.Enemy_ID-> Spawn only the enemy, whose Enemy_ID=randomnumber

Is it more clear what I mean now? How do I have to adjust the second code in order to make it work correctly?
B
17
S
7
G
2
Posts: 110
Reputation: 2,665

Post » Sat Mar 22, 2014 5:34 am

You don't, that's just it. You can't spawn a specific Family member, you have to spawn the specific object that belongs to a family.
ImageImageImage
B
71
S
22
G
247
Posts: 3,756
Reputation: 137,558

Post » Sat Mar 22, 2014 6:48 am

Message: Lindas is not yet permitted to post plain text URLS (300 rep required). 1 URLS removed. Why?
Well done TaylorMade SLDR Driver ()
Banned User
B
2
Posts: 1
Reputation: 158

Post » Sat Mar 22, 2014 8:25 am

In my game im created an object called "spawnpoint" this object have an variable called for example "EnemyId", when this object isOnScreen then im creating enemy belongs to this variable number at position of spawnpoint and destroy it.
B
2
G
1
Posts: 8
Reputation: 591

Post » Sat Mar 22, 2014 4:57 pm

Damn, I can`t do it like this? That makes me sad. Now I gotta write if-conditions for each of the 40 enemies... but thanks, guys!
B
17
S
7
G
2
Posts: 110
Reputation: 2,665


Return to How do I....?

Who is online

Users browsing this forum: dop2000, Yahoo [Bot], zenox98 and 8 guests