【问题标题】:Error in assigning a turtle to a turtles-own variable将乌龟分配给乌龟自己的变量时出错
【发布时间】:2014-03-25 17:02:51
【问题描述】:

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

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

【问题讨论】:

    标签: simulation netlogo multi-agent


    【解决方案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 ]
    

    【讨论】:

    • 实际上,我自己早先就想到了这一点——令人惊讶的是,NetLogo 对括号如此着迷。不过谢谢!
    猜你喜欢
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 2015-06-14
    • 1970-01-01
    相关资源
    最近更新 更多