Search code examples
netlogo

I am trying to model infection between mosquito and human, when setting different states for human it works but for mosquito it does not work


I am trying to model infection between mosquito and human, when setting different states for human it works but for mosquito it does not work. this is the code I used to set mosquito agent to infected

    ask one-of turtles [set infected? true]
      if infected? [ set color blue]

The complete code is

breed [human humans]
breed [mosquito mosquitoes]


turtles-own
[
  infected?           ;; If true, the person is infected
  recovered?              ;; If true, the person has lived through an infection.
  susceptible?        ;; Tracks whether the person was initially susceptible
  
]


;;; SETUP PROCEDURES
to setup
  clear-all
  setup-human
 setup-mosquito
  reset-ticks
end
to setup-human
  create-turtles 100
  [
    setxy random-xcor random-ycor
    set recovered? false
    set infected? false
    set susceptible? true

    set shape "person"
    set color white
    set size 1
    ask one-of turtles[set infected? true] 
    if infected? [set color red]
  ]
end
to setup-mosquito
  create-turtles 10
  [
    setxy random-xcor random-ycor
    set susceptible? true
    set infected? false

    set shape "bug"
    set color brown
      set size 1
    ask one-of turtles [set infected? true]
      if infected? [ set color blue]
   ]
  end

  to go
  ask turtles
  [
    set heading  random 360
    forward random 2
  ]
  tick
end

  

Solution

  • The bracketing is unclear in your code, I can't see what the if statement is within. But if the goal is to do several actions when you infect the mosquito, then put them all together like:

    ask one-of turtles
    [ set infected? true
      set color blue
    ]