选择品种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
答案 0 :(得分:1)
将if breed = A [set color red]
替换为if breed = A [ask myself [set color red]]
。这样行吗?
关键字myself
是指执行询问的人,而不是乌龟执行被要求执行的命令。
答案 1 :(得分:0)
如果我了解您要实现的目标,那么我认为解决方案可以很简单:
to go
ask one-of A [
set color red
create-obj
]
end
通常,您几乎不需要使用if breed = ...
模式。如果发现自己这样做,很可能以错误的方式解决问题,通常可以实现所需的目标。 (当然,我们总是欢迎您在这里问这个问题。)