从嵌套询问设置海龟的变量

Setting turtle's variable from nested ask

我是 netlogo 的新手,所以我的问题可能很愚蠢。如果两只或多只海龟面对面,我想将变量 conv 设置为 true。 所以我遍历所有海龟并询问它们的视锥中是否有海龟。如果有的话,我会问那些海龟 conv 对他们来说是否是假的,我是否在他们的视野范围内。如果是这种情况,我需要为彼此面对的两只海龟设置 conv true。 下面的代码显然是行不通的,但我不知道怎么写不同的。

ask turtles[
ask other turtles in-cone 4 90[
    if (not conv) and (member? myself other turtles in-cone 4 90)[
        set conv true
        set [conv] of myself true]
    ]
]

关键字set指示海龟将自己的变量(或全局变量)设置为指定值。这意味着您需要更改为要为其更改变量的海龟的视角。这是一个完成视角变化的完整模型。

to testme
  clear-all
  create-turtles 100
  [ setxy random-xcor random-ycor
    set color blue
  ]
  ask turtles
  [ ask other turtles in-cone 4 90
    [ if member? myself other turtles in-cone 4 90
      [ set color red 
        ask myself [ set color red ]
      ]
    ]
  ]
end

基本上,您需要的不是 set [conv] of myself true],而是 ask myself [set conv true]