I am trying to move a turtle towards it's offspring based on a shared variable. In my initial code I ask a male (breed) that has a display, but not a bower, to establish a bower (different breed) by hatching. I use create-link-with myself to so that the male and the bower share a variable called bird-id.
to establish-bower
ask males[
if has-bower? = false[
if has-display? = true[
hatch 1 [
set breed bowers
set color yellow
set bower-id who
set shape "house"
create-link-with myself
]
]
]
]
end
In the second part of my code, I ask males that have a bower and a display to return-to-bower. If their distance to THEIR OWN bower is greater than 0, the male faces that bower and moves forward one. If the distance is 0, two other variables and the energy are adjusted and the male moves a bit randomly.
to return-to-bower
ask males[
if has-bower? = true[
if has-display? = true[
(ifelse
distance one-of bowers with [bird-id = (bird-id of myself)] > 0[
face one-of bowers with [bird-id = (bird-id of myself)]
fd 1]
distance one-of bowers with [bird-id = (bird-id of myself)] = 0[
set has-display? false
set nr-display nr-display + 1
rt random 50
lt random 50
fd 1
set energy energy - 3])
]
]
]
end
I have trouble coding the part that identifies a bower as belonging to the male that made it. So far I have
bowers with [bird-id = (bird-id of myself)]
This obviously doesn't work, but it conveys what I want to do.
How can I write this part?