How do I inherit variables from random parents?

0 favourites
  • 2 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • So I'm making a small natural-selection sim and need to make offspring inherit variables values from parents.

    However, I have no clue how to do it. The biggest obstacle is instance selecting, since the way (I hope) the inheritance goes is that for each stat (speed, sight, etc) it would pick one of the parent to inherit that from (so if one parent has a speed of 150 and the other 170, the offspring has a 50/50 chance for 170, repeat for other stats). However, how would I pick between parent A, parent B, and the offspring?

    Or would it be easier to convert it to a sort of mitosis, where the parent just duplicates?

    Thanks in advance.

    Tagged:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • The common way to do this is by adding the object to a family. Move all variables and behaviors to the family level. Then you will be able to pick family instance and sprite instance independently in the same event, and copy values from one to another.

    With two parent instances it may be a bit trickier. You may temporary set an instance variable "IsParent" for two parents. (make sure it's not set for all other instances). Then pick a random parent.

    Family IsParent=1
    Pick random Parent instance
    ... Sprite set speed to Parent.speed
    
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)