How to find a patch with a specific ID where there is a red turtle?

不打扰是莪最后的温柔 提交于 2019-12-25 03:59:09

问题


I have a problem with this code piece.

ask persons [
set my-ID-polygon [ID-polygon] of patch-here
[patch-here] of turtles with [color = red and shape = "x"] with [ID-polygon = my-ID-polygon] ]

I obtain this error message:

TURTLES breed does not own variable MY-ID-POLYGON

In fact, I would like to have the patch with ID-polygon = my-ID-polygon where there is a turtle with color = red and shape = "x".

Thanks in advance for your help.


回答1:


I guess that my-ID-polygon is a persons variable, but in the following expression:

turtles with [color = red and shape = "x"] with [ID-polygon = my-ID-polygon]

The second with clause is executed in the context of turtles.

That being said, if you want:

the patch with ID-polygon = my-ID-polygon where there is a turtle with color = red and shape = "x"

It translates to something like this in NetLogo code:

ask persons [
  show one-of patches with [
    ID-polygon = [ my-ID-polygon ] of myself and
    any? (turtles-here with [ color = red and shape = "x" ])
  ]
]

I use one-of in case many patches fit the criteria.

The with clause is executed in the context of patches. In order to get the value of the my-ID-polygon variable of the asking person, you need to "move up" to the outer context using of myself.



来源:https://stackoverflow.com/questions/23976538/how-to-find-a-patch-with-a-specific-id-where-there-is-a-red-turtle

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