我怎样才能解决这个错误(你不能在补丁上下文中使用 my_ 区域,它是一个 turtle-only)?

How can I solve the error (you can not use my_ area in a patch context, it is a turtle-only)?

如果我之前定义的批次,我希望海龟回到它们的区域。问题是我收到一个错误

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

好的,这个问题和你之前的问题是一样的。请尝试理解答案,而不是简单地复制代码。否则,你会一直问同样的问题。

你有 'area' 作为补丁变量和 'my_area' 作为海龟变量。

您需要意识到要修补的海龟是独一无二的,因为一只海龟一次只能出现在一个地方。因此,海龟可以访问它所在的补丁所拥有的变量,而无需指定补丁。所以像这样的代码是可以的:

ask turtles with [area = 1] [ ]

这是因为它等同于:

ask turtles with [ [area] of patch-here = 1] [ ]

但是,一个小块不能访问一个海龟拥有的变量,因为在同一个小块上可能有多个小海龟。例如,如果您要求一个补丁将其 pcolor 设置为 color,并且补丁上有红海龟和一只蓝海龟,它如何知道选择哪种颜色?

您的错误显示 "you can not use my_area in a patch context, it is a turtle-only"。这告诉你你试图让一个补丁使用 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