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

0 favourites
  • 7 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • 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

  • You just create Enemy2 and set it's Enemy_type to2.

  • Obviously I failed in describing my problem clearly 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?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Well done TaylorMade SLDR Driver ()

  • 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.

  • 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!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)