问题
I have a problem with this code piece.
ask persons [
set my-ID-polygon [ID-polygon] of patch-here
[patch-here] of turtles with [color = red and shape = "x"] with [ID-polygon = my-ID-polygon] ]
I obtain this error message:
TURTLES breed does not own variable MY-ID-POLYGON
In fact, I would like to have the patch with ID-polygon = my-ID-polygon where there is a turtle with color = red and shape = "x".
Thanks in advance for your help.
回答1:
I guess that my-ID-polygon
is a persons
variable, but in the following expression:
turtles with [color = red and shape = "x"] with [ID-polygon = my-ID-polygon]
The second with
clause is executed in the context of turtles
.
That being said, if you want:
the patch with ID-polygon = my-ID-polygon where there is a turtle with color = red and shape = "x"
It translates to something like this in NetLogo code:
ask persons [
show one-of patches with [
ID-polygon = [ my-ID-polygon ] of myself and
any? (turtles-here with [ color = red and shape = "x" ])
]
]
I use one-of in case many patches fit the criteria.
The with
clause is executed in the context of patches. In order to get the value of the my-ID-polygon
variable of the asking person, you need to "move up" to the outer context using of myself
.
来源:https://stackoverflow.com/questions/23976538/how-to-find-a-patch-with-a-specific-id-where-there-is-a-red-turtle