错误:在网络徽标中"a patch cannot access a variable of a turtle without specifying which turtle"



我想防止乌龟访问它以前访问过的补丁。我正在开发代码,但出现了以下错误:error:"补丁不能在不指定哪只乌龟"的情况下访问乌龟的变量;。

我确信这是另一个语法错误。但是,我找不到这个错误。我试着简化代码,让你们更容易帮助我。任何形式的帮助都是受欢迎的。

turtles-own: patchVisited
setup:   set patchVisited (list patch-here)
go:   set patchVisited lput patch-here patchVisited
move:
let availablePatch [neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ]] of patch-here
let neighAvailable count availablePatch 
move-to max-one-of availablePatch [resource-value]

更改

let availablePatch [ neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ] ] of patch-here

let availablePatch neighbors with [not member? self [patchVisited] of myself and resource-value > 0.2 ]

你不需要neighbors of patch-here,这就是neighbors的意思。

一般来说:(1(NetLogo突出显示了带有语法错误的行。这对我们(和您(来说都是有用的信息,因此请将其包含在问题描述中。(2( 在你的代码中进行较小的更改-在继续之前让较小的更改生效。在这种情况下,你可以只让一只乌龟四处移动,然后做一些类似的事情:

ask neighbors with [not member? self [patchVisited] of myself] [set pcolor red]

然后又把补丁变白了。

最新更新