Netlogo Patch 无法在不指定哪个海龟的情况下访问海龟变量

Netlogo Patch can't access a turtle variable without specifying which turtle

我正在尝试设置一个程序来更改我的细胞样斑块外部斑块的颜色,以便可以轻松识别哪个细胞是哪个细胞。到目前为止,我有以下代码,但在尝试运行该程序时遇到问题。代码如下

globals [
  radius 
]
patches-own [
  patch-state
  CellID
]

to setup
  clear-all
  set radius 2
  create-turtles #cells [
    ifelse mode =  "Restricted"
    [ setxy random-float #units - random-float #units random-float #units - random-float #units ]
    [ setxy random-xcor random-ycor ]
   ]
  reset-ticks
end

to go
  expand-cells
  make-membrane
  tick
end

to expand-cells
  set radius radius + 1
  ask turtles [ ask patches in-radius radius [
    if pcolor = black or CellID = [who] of myself + 1 [
      build-up-cells 
    ]
   ]
  ]
  ask patches with [ pcolor = black ] [
   set patch-state "X"
  ]
end

to build-up-cells
  set pcolor [ color ] of myself
  set CellID [who] of myself + 1
end

to make-membrane
  ask patches with [pcolor != black] [
    ifelse not any? neighbors with [ CellID = [who] of myself + 1 ]
    [ set patch-state "I" ]
    [ set patch-state "M" ]
  ]
  ask patches with [ patch-state = "M" ] [
    set pcolor pcolor - 1
  ]
  trim
end

to trim
end

我得到的错误是: 如果不指定是哪只海龟,补丁就无法访问海龟变量。 补丁 40 6 运行 OF 时出错 由过程 MAKE-MEMBRANE 调用 由程序 GO 调用 由按钮调用 'go-once'

错误是由于 who 的错误使用造成的。如果你看一下 Netlogo dictionary,你会发现 who 是一个 turtle 变量,但是你 运行 make-membrane 在补丁上。

我想,你想做的是检查是否有任何邻居不属于相同的单元格(即不属于相同的 CellID),如果有,使该补丁成为膜补丁。

ifelse any? neighbors with [ CellID != [CellID] of myself]
    [ set patch-state "M" ]
    [ set patch-state "I" ]