adkane
adkane

Reputation: 1441

How can I keep track of a turtle's parents once they die?

In my model parents produce offspring. The following is a procedure for the females to produce their young and here the young keep track of the identity of their parents.

  to reproduce
  if count mates > 0 [
    hatch 3 [
     set mother myself
     set father one-of [mates] of mother
]]

Tragically, their parents can die and so the mother and father variables become nobody. Is there a way I can keep these IDs from turning into nobody?

Upvotes: 1

Views: 39

Answers (1)

JenB
JenB

Reputation: 17678

This is one of the (very rare) cases where it is sensible to use who. In your case, I'd have two variables for each parent - one as you have already so you can easily make statements like face mother and the other stores the who so you can track lineages after the parents die. Your code would then look like:

to reproduce
  if count mates > 0 [
    hatch 3 [
     set mother myself
     set motherID [who] of mother
     set father one-of [mates] of mother
     set fatherID [who] of father
]]

Upvotes: 2

Related Questions