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



我正在尝试设置一个程序来更改我的细胞样贴片的外部贴片的颜色,这样就可以很容易地识别哪个细胞是哪个。到目前为止,我有以下代码,但我在尝试去一次程序时遇到了问题。代码低于

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调用由按钮调用"一次性">

错误是由于who的错误使用造成的。如果您查看Netlogo字典,您会发现who是一个海龟变量,但您在补丁上运行make-membrane

我想,你想做的是检查,如果有任何邻居,它们不属于同一个细胞(即没有相同的CellID(,如果有,就把那个补丁做成膜补丁。

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

最新更新