NetLogo 中刻度的问题
Problems with ticks in NetLogo
我正在尝试了解并查看是否可以更改以下内容:
我的代码有 2 次迭代。与配置完全一样。通过单击全部设置按钮,然后单击 go once 按钮 4 次。调用第二次迭代。但是,第二次迭代从第 1 个节拍开始,而不是从第 0 个节拍开始。为什么会这样?有办法解决吗?
globals [ iteration ]
patches-own [ scale-patch ]
to setup-world
clearMethod
random-seed 1
ifelse iteration = 0
[setup-layers]
[setup-layers-2]
setup-turtles
reset-ticks
end
to clearMethod
clear-ticks
clear-turtles
end
to setup-all
clear-all
random-seed 1
ifelse iteration = 0
[setup-layers]
[setup-layers-2]
setup-turtles
reset-ticks
end
to setup-layers
ask patches [
set scale-patch random 10
set pcolor scale-color blue scale-patch -8 12 ]
end
to setup-layers-2
ask patches [
set scale-patch random 10
set pcolor scale-color green scale-patch -8 12 ]
end
to setup-turtles
crt 1 [ set color black ]
end
to go
moveproc
let n count turtles
if n = 0
[
ifelse iteration = 0
[
set iteration 1
setup-world
]
[
stop
]
]
tick
end
to moveproc
ask turtles [
right random 360
fd 1
if ticks >= 3
[
die
]
]
end
提前致谢
更改迭代的时刻在 go
过程中(即 set iteration 1 setup-world
)。但是,go
过程也以 tick
结束。这意味着当您更改迭代时,NetLogo 将首先执行所有新的设置,包括 reset-ticks
(将刻度变为 0),然后执行 tick
(将刻度变为 1)。
如果您不希望这种情况发生并且需要维护此结构(即 go
执行设置),您可以重新安排 go
过程,以便 tick
发生在之前 你检查迭代变化的条件:
to go
moveproc
tick
let n count turtles
if n = 0 [
ifelse iteration = 0
[set iteration 1
setup-world]
[stop]
]
end
PS:您提供的是一个极好的最小可重现示例
我正在尝试了解并查看是否可以更改以下内容:
我的代码有 2 次迭代。与配置完全一样。通过单击全部设置按钮,然后单击 go once 按钮 4 次。调用第二次迭代。但是,第二次迭代从第 1 个节拍开始,而不是从第 0 个节拍开始。为什么会这样?有办法解决吗?
globals [ iteration ]
patches-own [ scale-patch ]
to setup-world
clearMethod
random-seed 1
ifelse iteration = 0
[setup-layers]
[setup-layers-2]
setup-turtles
reset-ticks
end
to clearMethod
clear-ticks
clear-turtles
end
to setup-all
clear-all
random-seed 1
ifelse iteration = 0
[setup-layers]
[setup-layers-2]
setup-turtles
reset-ticks
end
to setup-layers
ask patches [
set scale-patch random 10
set pcolor scale-color blue scale-patch -8 12 ]
end
to setup-layers-2
ask patches [
set scale-patch random 10
set pcolor scale-color green scale-patch -8 12 ]
end
to setup-turtles
crt 1 [ set color black ]
end
to go
moveproc
let n count turtles
if n = 0
[
ifelse iteration = 0
[
set iteration 1
setup-world
]
[
stop
]
]
tick
end
to moveproc
ask turtles [
right random 360
fd 1
if ticks >= 3
[
die
]
]
end
提前致谢
更改迭代的时刻在 go
过程中(即 set iteration 1 setup-world
)。但是,go
过程也以 tick
结束。这意味着当您更改迭代时,NetLogo 将首先执行所有新的设置,包括 reset-ticks
(将刻度变为 0),然后执行 tick
(将刻度变为 1)。
如果您不希望这种情况发生并且需要维护此结构(即 go
执行设置),您可以重新安排 go
过程,以便 tick
发生在之前 你检查迭代变化的条件:
to go
moveproc
tick
let n count turtles
if n = 0 [
ifelse iteration = 0
[set iteration 1
setup-world]
[stop]
]
end
PS:您提供的是一个极好的最小可重现示例