netlogoneighbours

Netlogo: asking a turtle to count its neighbors


I´m asking a turtle to count its neighboring turtles that are healthy with the following code

let healthy-neighbors count turtles-on neighbors with [infected? = false]

I get the following: You can´t use INFECTED? in a patch context, because INFECTED? is turtle-only

My mistake must be basic, but can't find it, any help?


Solution

  • NetLogo is seeing that as turtles-on (neighbors with [infected? = false), and since neighbors gives an agentset of patches, the with clauses is expecting patches, but patches do not have infected?, as it says in the error.

    What you probably want is let healthy-neighbors count (turtles-on neighbors) with [infected? = false]. The parentheses will tell NetLogo to get the turtles from the neighboring patches first, then filter them with with.