我该如何解决该错误(您不能在补丁程序上下文中使用my_区域,它仅适用于乌龟)?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我该如何解决该错误(您不能在补丁程序上下文中使用my_区域,它仅适用于乌龟)?相关的知识,希望对你有一定的参考价值。
如果我之前定义的批次,我希望海龟再次回到它们的区域。问题是我遇到了错误
you can not use my_ area in a patch context, it is a turtle-only
按钮是
to back_from_event
ask turtles with [ area = 1 ] [ move-to one-of patches with [ (not any? other turtles-here) and ( area = my_area ) ] ]
end
如下定义的斑块和海龟在区域(2,3,4,5)中,并移至区域1,我需要它们再次回到该区域:
to define_areas
ask patches with [ (pxcor > -3) and (pxcor < 3) and (pycor > -3) and (pycor < 3) ] [ set pcolor white set area 1 ]
ask patches with [ (pxcor > 5 ) and (pxcor < 16 ) and (pycor > 4) and (pycor < 16) ] [ set pcolor white set area 2 ]
ask patches with [ (pxcor < -5 ) and (pxcor > -16 ) and (pycor > 4) and (pycor < 16) ] [ set pcolor white set area 3 ]
ask patches with [ (pxcor < -5 ) and (pxcor > -16 ) and (pycor < -4) and (pycor > -16) ] [ set pcolor white set area 4 ]
ask patches with [ (pxcor > 5 ) and (pxcor < 16 ) and (pycor < -4) and (pycor > -16) ] [ set pcolor white set area 5 ]
end
您需要意识到的是,要修补的乌龟是唯一的,因为一次只能将一只乌龟放在一个地方。因此,乌龟无需指定补丁即可访问其所坐补丁所拥有的变量。这样的代码就可以了:
ask turtles with [area = 1] [ ]
这是因为它等效于:
ask turtles with [ [area] of patch-here = 1] [ ]
但是,一个补丁无法访问一个乌龟拥有的变量,因为同一补丁上可能有多个乌龟。例如,如果您要求某个色块将其pcolor
设置为color
,并且该色块上有红色乌龟和蓝色乌龟,它怎么知道要选择哪种颜色?
您的错误说:“您不能在补丁程序上下文中使用my_area,它仅适用于乌龟”。就是说,您尝试使用my_area变量来打补丁,但该变量归海龟所有。因此,您没有告诉它从哪只乌龟那里获得my_area。这是您拥有的:
to back_from_event ask turtles with [ area = 1 ] [ move-to one-of patches with [(not any? other turtles-here) and (area = my_area)] ] end
我假设您希望补丁的面积与执行询问的乌龟的my_area相同。那就是myself
的目的。
to back_from_event
ask turtles with [ area = 1 ]
[ move-to one-of patches with [(not any? other turtles-here) and (area = [my_area] of myself)]
]
end
以上是关于我该如何解决该错误(您不能在补丁程序上下文中使用my_区域,它仅适用于乌龟)?的主要内容,如果未能解决你的问题,请参考以下文章
片段活动错误中的ListView Adapter上下文,我该怎么办?
Pytesseract:“TesseractNotFound 错误:tesseract 未安装或不在您的路径中”,我该如何解决?