只有观察者可以询问所有海龟-NetLogo错误

时间:2018-12-10 23:23:46

标签: netlogo

我是Netlogo的新用户, 虽然当我检查代码时没有任何问题。但是,当我一段时间运行程序时,它会引发错误消息

  

只有观察者可以询问所有乌龟的集合。乌龟0运行ASK时出错。由过程EXIT调用,由过程Customer,GO和按钮“ go”调用

to go
customer
end

to setup-turtles
create-turtles 1
ask turtles
[
set shape "person"
set size 3
set heading -90
fd 10
setxy 15 -15
set color red
]
end

to customer
ask turtles
[
set products ( products )
rt (random 360)
fd 1
if patch-here = one-of patches with
[
  pcolor = green
]
[
  set pcolor orange
  set products (products + 1)
]
if patch-here = one-of patches with
[
  pcolor = gray
]
[exit]
show count patches with
[pcolor = green ]


move-to one-of patches with
[
  pcolor = black
]

]
end



to exit
ask turtles
[
ifelse patch-here = one-of patches with
[
  pcolor = gray
]
[ifelse count products >= 2
  [
    die
  ]
  [move-to one-of patches with
    [
      pcolor = green or pcolor = black
    ]
  ]
]
  [
    die
  ]
move-to one-of patches with
  [pcolor = green
  ]

move-to one-of patches with
    [pcolor = black
    ]


  ]

end

1 个答案:

答案 0 :(得分:2)

在您的客户程序中,您拥有

ask turtles
[ ...
  if patch-here = one-of patches with [pcolor = gray]
  [ exit ]
  ...
]

因此,任何位于灰色补丁上的乌龟都会调用退出过程。符合条件的每只乌龟都进入退出程序。一旦进入该过程,第一个命令(在退出过程中)即到达ask turtles。因此,一只乌龟正在要求所有的乌龟做某事。

这被NetLogo语言明确禁止,部分原因是它是初学者错误的常见来源,并且通常既不必要又效率低下。您已经选择了乌龟要退出,这只特定的乌龟需要做什么才能真正退出。他们不太可能需要识别灰色斑点上的所有海龟。