Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

How do I code in NetLogo that one kind of turtle is hatched if another kind of turtle dies?

ambernetlogo

New Coder
How do I code in NetLogo that one kind of turtle is hatched if another kind of turtle dies?

The turtles in my code are 'zombies' and 'humans'. This is a part of my code in NetLogo, my intention is to code it so a zombie will be hatched when a human is killed by a zombie. How do I do this? Because now no zombies are hatched and no humans are killed. I can see that because there are no zombies added when I run the code. I also have a graph in the model that shows the human death causes and that shows that no humans are killed by zombies, they all die of age or density.

Code:
to zombies-kill-and-infect
    ; zombies kill and infect humans

      ask humans [
        let zombies-nearby zombies in-radius 5
        let r random 100
        if r < 3 [ die ] ; zombies have a 3% chance of killing the human
        if r < 3 + odds-of-killing - protection [
          ask one-of humans-here [ die ] ; successfully killed a human!
          set humans-killed-by-zombies humans-killed-by-zombies + 1
          set dead-humans dead-humans + 1
      ask zombies [
            if humans-killed-by-zombies = 1 [ hatch 1 ]; human is killed by zombie so a zombie is born
            hatch-zombies 1 [ set age 0 ]
            
          ]
        ]
      ]
 
Back
Top Bottom