在netlogo中处理补丁时,正确的语法是什么



我有以下代码,但当尝试运行它时,我收到一条消息,上面写着"期望一个文字值";,并突出显示calidad
我猜是因为我如何写括号有问题?

to check-if-dead
if habitat = "escarabajo" [
ask escarabajos [
if count escarabajos-here > capacidad-de-carga-bosques [die] ; beetles that reach patches that already have a # above the carrying capacity die 
if patch-here = [calidad "baja"] [
if random 100 > probabilidad-de-supervivencia-calidad-baja [die]
]
if patch-here = [calidad "alta" ] [
if random 100 > probabilidad-de-supervivencia-calidad-alta [die]
]
]
]

在我的宇宙中有高质量的补丁和低质量的补丁,我希望海龟以一定的概率死亡(由滑块决定(,这取决于它们降落的补丁。。。

您可能想要if [calidad] of patch-here = "baja":

to check-if-dead
if habitat = "escarabajo" [
ask escarabajos [
if count escarabajos-here > capacidad-de-carga-bosques [die] ; beetles that reach patches that already have a # above the carrying capacity die 
if [calidad] of patch-here = "baja" [
if random 100 > probabilidad-de-supervivencia-calidad-baja [die]
]
if [calidad] of patch-here = "alta" [
if random 100 > probabilidad-de-supervivencia-calidad-alta [die]
]
]
]
end

但请注意,海龟总是生活在一个补丁上,所以您可以直接引用patches-own变量作为这种情况的捷径(同样,您也可以在海龟上下文中使用pcolor(:

to check-if-dead
if habitat = "escarabajo" [
ask escarabajos [
if count escarabajos-here > capacidad-de-carga-bosques [die] ; beetles that reach patches that already have a # above the carrying capacity die 
if calidad = "baja" [
if random 100 > probabilidad-de-supervivencia-calidad-baja [die]
]
if calidad = "alta" [
if random 100 > probabilidad-de-supervivencia-calidad-alta [die]
]
]
]
end

最新更新