如何在有红龟的情况下找到具有特定ID的补丁?

时间:2014-06-01 03:35:32

标签: netlogo

我的代码片有问题。

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] ]

我收到此错误消息:

TURTLES breed does not own variable MY-ID-POLYGON

事实上,我希望补丁有ID-polygon = my-ID-polygon,其中有一只颜色=红色且形状=" x"的海龟。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

猜测 my-ID-polygonpersons变量,但在以下表达式中:

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

第二个with子句在turtles

的上下文中执行

话虽如此,如果你想:

  

具有ID-polygon = my-ID-polygon的补丁,其中有一只颜色=红色且形状=" x"

的乌龟

它在NetLogo代码中转换为类似的内容:

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

如果许多补丁符合条件,我会使用one-of

with子句在补丁的上下文中执行。为了获得询问者的my-ID-polygon变量的值,您需要向上移动"使用of myself到外部环境。