3

Is there a way to spawn turtles during simulation even if they died. In my simulation fish are eating plankton, so if they encounter plankton the plankton dies/gets eaten. However, when a fish can't eat plankton anymore it will die because it doesn't get energy from plankton anymore by eating it. So when all the fish have died the plankton should come back; due to migration etc. and grow immensively. I am not sure how to implement this? The create function doesn't work here, only in the setup.

to plankton-reproduce
  if random-float 100 < reproduce-plankton [
    set energy (energy / 2)
    hatch 1 [setxy random-xcor random-ycor]
  ]
  if count plankton < 10 [
    create-plankton 20
    setxy random-xcor random-ycor
  ]

error: you can't use create-plankton in a turtle context, because create-plankton is observer only

mnovabox
  • 41
  • 5

2 Answers2

2

I think I may understand the question.

to to have a turtle create turtles use HATCH. Your code would work (if I understand it) if you used

hatch-plankton 20

instead of

 create-plankton 20

Did I get it right? Turtles hatch , patches spawn and observer creates. the turtles hatched will be identical to the hatching turtles and will all be in a lump where hatch was called. Assuming that you do not want that. use

hatch-plankton 20 [setxy random-xcor random-ycor]
Seth Tisue
  • 29,985
  • 11
  • 82
  • 149
King-Ink
  • 2,096
  • 12
  • 18
0

I have incorporated this in the code, but when the count of plankton is zero, there will be no plankton respawned, this is because all plankton is dead and cannot be hatched. Do you know another way to spawn plankton or respawn turtles in general during a simulation even if they die? Beneath the code to reproduce plankton:

to plankton-reproduce
  while [count plankton != 0 and count plankton < 3000]
    [ if random-float 100 < reproduce-plankton
      [set energy (energy / 2)
       hatch-plankton 1 [setxy random-xcor random-ycor]]]
  if count plankton = 0
  [set energy 1
  hatch-plankton 20 [setxy random-xcor random-ycor]]
end
mnovabox
  • 41
  • 5