将乌龟分配给海龟自己的变量时出错

时间:2014-03-25 17:02:51

标签: simulation netlogo multi-agent

我有一只乌龟的视锥被定义为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 ]

在第三行。这里有什么问题?

1 个答案:

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