我对这段代码有一个问题。
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-polygon
是persons
变量,但在以下表达式中:
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
"上移"到外部上下文。