【问题标题】:Setting turtle's variable from nested ask从嵌套询问设置海龟的变量
【发布时间】:2019-04-13 16:26:30
【问题描述】:

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

【问题讨论】:

    标签: nested netlogo


    【解决方案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
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      相关资源
      最近更新 更多