1

我收到错误消息:

MEMBER? expected input to be a string or list or agentset but got the number 0 instead.

在运行以下 NetLogo 代码期间:

to find-flockmates  ;; turtle reporter
  ;; latch on to the nearby birds
  set flockmates-infront other birds in-cone vision cone-infront-degree
  set flockmates-sidewise other birds in-cone vision cone-sidewise-degree

  ;; agentset substraction
  if (count flockmates-infront > 0)[
    set flockmates-sidewise (flockmates-sidewise with [not member? self flockmates-infront])  
    ] 
end

有人可以告诉我我做错了什么或另一个可能的减法两个代理集的解决方案吗?

4

1 回答 1

4

我现在明白了!很难从您发布的初始代码示例中猜到它,起初我没有意识到这flockmates-sidewiseflockmates-infront品种变量。

因此,在这一行中:

set flockmates-sidewise (flockmates-sidewise with [not member? self flockmates-infront])

...flockmates-infront是指执行with块的代理的品种变量,而不是运行find-flockmates报告器的代理的变量。0(如果它还没有被初始化,那很可能是。)你想要的是:

set flockmates-sidewise (flockmates-sidewise with [
    not member? self [flockmates-infront] of myself
])

myself意思是“要求我做我现在正在做的事情的乌龟或补丁”。

我猜您在创建少于 10 只鸟时没有收到错误,因为if在这种情况下您根本无法执行该行。

于 2012-12-15T23:33:51.363 回答