在一个程序中,我想为每个海龟(代理人)启动一个计时器,当从#34; shape2" to" shape1",该计时器在10个刻度后到期,形状变回" shape1" 。我的程序只有在我按下" go"它仅适用于计算的前10个滴答。之后它没有被调用。我已将此程序名称称为"更改"在GO区块。
to change
let test one-of breed-here with [ shape = "shape2" ]
if test != nobody and [ ticks ] of test = 10
[ask breed with [ shape = "shape2" ]
[ set shape "shape1" ]
]
end
GO块语句是:
to Go
ask breed with [ shape = "shape2" ] [ change ]
end
答案 0 :(得分:1)
以下是使用补丁的插图。 (颜色代表形状。)
patches-own [shape-timer]
globals [s1 s2]
to setup
ca
set s1 blue ;"shape" 1
set s2 red ;"shape" 2
ask patches [set pcolor one-of (list s1 s2)]
end
to temp-change-shape
set pcolor s2
set plabel "temp"
set shape-timer 10
end
to update
set shape-timer (shape-timer - 1)
if (shape-timer = 0) [
set plabel ""
show "changing back!"
set pcolor s1
]
end
to go
ask patches with [pcolor = s2 and shape-timer > 0] [
update
]
ask one-of patches with [pcolor = s1] [
temp-change-shape
]
end
更好的解决方案使用table
扩展,将日期(滴答)映射到需要在每个日期更新的代理。 (这样您就不必每个代理检查每个代理,以确定是否有时间更新它。)