Can I spawn objects that inherit features from their parent?

Get help using Construct 2

Post » Mon Oct 19, 2015 2:45 am

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.
B
3
S
1
Posts: 1
Reputation: 277

Post » Mon Oct 19, 2015 5:55 am

@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...
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Post » Mon Oct 19, 2015 2:05 pm

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.
https://www.ravenheart.ca/home
Company name changed to avoid Facebook-type shenanigans

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
22
S
6
G
1
Posts: 1,414
Reputation: 4,822


Return to How do I....?

Who is online

Users browsing this forum: BadMario, stevenode, Yahoo [Bot] and 11 guests