从嵌套的ask设置乌龟的变量

时间:2019-04-13 16:26:31

标签: nested netlogo

我是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]
    ]
]

1 个答案:

答案 0 :(得分:1)

关键字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]