I'm making a simulator where creatures can mutate and evolve over time. When the parent makes a baby, I want to copy the parent's variables (movement speed, jump force, size, etc) to the child, but with some mutation.
Basically, I want to do something like that:
- Set child's speed to parent.speed*random(-0.1, 0.1)
- Set child's jumpForce to parent.jumpForce*random(-0.1, 0.1)
But obviously, because of the way construct picks objects, either I pick only the child and I can't "see" the parent's variables, or I pick both the parent and the child, but I will then affect the instance variables of both, which I don't want.
Possible solution I can think of:
- I create a local variable for each instance variable, copy the parent's variables to these local vars, then pick the child and copy the local vars to the child's var
- Create an array and do the same thing as ↑
- I create a family called "parent" and use that to talk to the parent (as the family) and the child (as the object itself) at the same time
Is there other easier ways that I can't think of?