我有一只乌龟的视锥被定义为5,120。现在,我想让乌龟指定最近的乌龟,其颜色与其朋友相同。我的代码返回错误
this code can't be run by a patch
这是我的代码
turtles-own [ friend ]
to-report checkForAttraction [ agent ]
if [color] of one-of turtles-on empty-patches = [color] of agent [
set friend min-one-of other turtles-on empty-patches with [color = [color] of agent ] [ distance myself ]
set attracted? 1
]
report actualVelocity
end
错误显示在
处[color = [color] of agent ]
在第三行。这里有什么问题?
答案 0 :(得分:1)
违规行的问题是解析with
已将empty-patches
作为其 agentset 参数。由于补丁没有color
变量,因此您无法对empty-patches
测试color = [color] of agent
,因此会出错。
但是你不想要测试empty-patches
:你想测试turtles-on empty-patches
!
如果有一些好的括号,你可以:
set friend min-one-of other (turtles-on empty-patches) with [color = [color] of agent ] [ distance myself ]