Netlogo: asking a turtle to count its neighbors

孤人 提交于 2021-01-29 20:21:17

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/62582411/netlogo-asking-a-turtle-to-count-its-neighbors

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!