如何找到一个补丁与特定的ID在哪里有一个红海龟



我对这段代码有一个问题。

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"的海龟。

提前感谢您的帮助。

猜测 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"上移"到外部上下文。

最新更新