我的代码片有问题。
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"的海龟。
提前感谢您的帮助。
答案 0 :(得分:2)
我猜测 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
到外部环境。