Can I spawn objects that inherit features from their parent?

0 favourites
  • 3 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • I'm a little new to Construct 2 and I'm trying to create an evolution simulator that allows creatures to evolve new body features, and then reproduce and pass these features to their children.

    I have one creature sprite and each instance spawns with the variables Front_Limb, Back_Limb, Head, and Tail, all set to the default 0. Each instance then generates a random number between 0-10 and then adds 1 to one of the variables if it corresponds with the generated number (0:Body, 1:Tail, 2:Front Limbs, 3:Back Limbs 4:Head, 5-10 are blank) allowing the creature to randomly evolve new or improved features when it's born. When two creatures collide they then spawn a new instance of the creature which then goes through the same process of evolving new features.

    The part I'm having trouble with is getting the creatures to inherit their parent's features. For example, when a creature with a level 1 tail spawns a new creature I want the new instance to inherit the T1 variable and then either evolve a new feature or add to the inherited one giving it a level 2 tail.

    Currently I have it set up so that when the two collide, the new one sets all its variables in the format:

    CreatureCore is overlapping CreatureCore & CreatureCore is playing animation "Egg": CreatureCore Set Body to CreatureCore.Body, CreatureCore Set Tail to CreatureCore.Tail, and so on....

    I've looked through the manual and can't find anything on sharing variables except for in families and those apply the variables to all instances, not one at a time. Does anyone know if there is another way to pass variables between individual instances?

    Any help would be wonderful and greatly appreciated.

  • Critchalow

    it sounds like the "CreatureCore is overlapping CreatureCore" is the problem. That is ambiguous... C2 can't tell which instance you want to copy from, and which one to copy to.

    The way to work around that problem is to create a family (called something like CreatureFamily), and add CreatureCore to the family.

    Then you would compare "CreatureCore is overlapping CreatureFamily & CreatureCore is playing Egg". CreatureCore Set Body to CreatureFamily.Body, CreatureCore Set Tail to CreatureFamily.Tail, and so on....

    that way it is clear which is the source (parent) and which is the child...

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • C2 determines overlapping by Sprite.UID. You would probably have to track inheritance in your own instance variables though (like 'genus') or something and have the same idea applied to all relevant parts. You will also have to manually assign genus upon creating new objects.

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