我对乌龟/补丁上下文和观察者上下文之间的区别有疑问。 问题出现在我的代码的最后一行。我希望一定数量的补丁程序可以执行某些操作,而这个数量由我上面定义的变量定义。当我使用5个补丁中的n个问题时,它可以正常工作,但是当我用变量替换5个补丁时,它会给出错误消息(您不能在turtle / patch上下文中使用tick,因为TICK仅用于观察者)。 有谁知道为什么它不起作用?
patches-own [kans-op-ontbossing]
to setup
clear-all
ask patches [if (random 100) < bosdensiteit [set pcolor green]]
ask n-of world-height patches with [pxcor = pycor][set pcolor blue]
ask n-of world-height patches with [pxcor = max-pxcor / 2] [set pcolor grey]
ask n-of aantal-nederzettingen patches with [pcolor != blue and pcolor != grey] [set pcolor white]
reset-ticks
end
to go
if ticks = 75 [stop]
ask patches [set kans-op-ontbossing ontbossingsgevoeligheid + houtprijs + vraag-naar-landbouwgrond]
ontbos
tick
end
to ontbos
ask patches with [pcolor = green and (pxcor > 30 or pycor > 30)]
[if count (neighbors4 with [pcolor = grey]) >= 1 or count (neighbors4 with [pcolor = blue]) >= 1 or count (neighbors with [pcolor = white]) >= 1
[if random 300 < kans-op-ontbossing [set pcolor brown]]]
ask n-of (kans-op-ontbossing / 10) patches with [pcolor = grey and pxcor = ((max-pxcor / 2) + ticks)][ask patch-at 1 0 [set pcolor grey]]
end
谢谢!
答案 0 :(得分:2)
kans-op-ontbossing
是一个patches-own
变量。因此,您要让NetLogo根据所有补丁之间可能有所不同的变量来询问一些补丁。就像说ask n-of ( pcolor / 10 ) patches
一样-在这种情况下,这实际上没有任何意义。 n-of
的参数必须是单个数值,这就是5起作用的原因。据我所知,出现此特定错误的原因是,从NetLogo的角度来看,您正在尝试访问patches-own
变量,然后直接进入tick
调用。将kans-op-ontbossing
替换为观察者可以访问的值,那么您应该一切顺利。