创建新对象时改变颜色乌龟

Change color turtle when it creates a new object

选择品种 A 的代理时,它会创建一个新对象。我需要将此对象添加到它的列表 (agenda) 和邻居的列表中。如果我在下面的代码中没有出错,我会问你如何改变代理而不是对象的颜色。

谢谢

breed[objects object]
objects-own[att_1]

breed [A aa]
A-own[
  my-object
  agenda
]

to setup
  create-A 10
  ask A[
    set agenda []
  ]
end

to go
[
  ask one-of A[create-obj]
]
end

to create-object
   create-object 1[
      if breed = A
        [set color red] ; I want to assign this colour to A, not to the object      
        hide-turtle
        set att_1 random-float 1
        let this-object myself
        if (condition 1)
              [ let customers (turtle-set self in-link-neighbors with [breed = A])
                ask customers
                [
                  set agenda fput this-object agenda
                ]
              ]      
         ]
end

if breed = A [set color red] 替换为 if breed = A [ask myself [set color red]]。有用吗?

关键字myself指的是提出要求的人,而不是执行命令的乌龟。

如果我理解您要实现的目标,我认为解决方案可以很简单:

to go
  ask one-of A [
    set color red
    create-obj
  ]
end

通常,您几乎不需要使用 if breed = ... 模式。如果你发现自己这样做,你很可能以错误的方式解决问题,而且通常无法实现你想要的。 (当然,随时欢迎您在这里提问。)