只有观察者可以询问所有海龟 - NetLogo 错误
Only observer can ask all turtles - NetLogo error
我是 Netlogo 的新用户,
虽然当我检查代码时,没有问题。但是,当我 运行 程序一段时间后,它会抛出错误消息
Only the observer can ASK the set of all turtles. Error while turtle 0 running ASK. called by procedure EXIT called by procedure Customer, GO and by button '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
在您的客户程序中,您有
ask turtles
[ ...
if patch-here = one-of patches with [pcolor = gray]
[ exit ]
...
]
所以退出过程被灰色块上的任何海龟调用。每只满足该条件的海龟都会进入退出程序。一旦它进入该过程,第一个命令(在退出过程中)就是 ask turtles
。所以一只乌龟要求所有的乌龟做某事。
这被 NetLogo 语言明确禁止,部分原因是它是初学者错误的常见来源,通常既不必要又低效。您已经选择了要退出的乌龟,这只乌龟需要做什么才能真正退出。他们不太可能需要识别灰色斑块上的所有海龟。
我是 Netlogo 的新用户, 虽然当我检查代码时,没有问题。但是,当我 运行 程序一段时间后,它会抛出错误消息
Only the observer can ASK the set of all turtles. Error while turtle 0 running ASK. called by procedure EXIT called by procedure Customer, GO and by button '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
在您的客户程序中,您有
ask turtles
[ ...
if patch-here = one-of patches with [pcolor = gray]
[ exit ]
...
]
所以退出过程被灰色块上的任何海龟调用。每只满足该条件的海龟都会进入退出程序。一旦它进入该过程,第一个命令(在退出过程中)就是 ask turtles
。所以一只乌龟要求所有的乌龟做某事。
这被 NetLogo 语言明确禁止,部分原因是它是初学者错误的常见来源,通常既不必要又低效。您已经选择了要退出的乌龟,这只乌龟需要做什么才能真正退出。他们不太可能需要识别灰色斑块上的所有海龟。