从示例开始:
to make-new-car [freq x y head ]
if (random-float 100 < freq) and not any? turtles-on patch x y [
create-cars 1 [
setxy x y
set heading head
set color one-of base-colors
]
]
end
然而,我希望有更多的汽车品种——而不仅仅是一种汽车品种。我也想保持简单并坚持做 this(第一个功能与上面的相同):
to make-new-car [freq x y head ]
if (random-float 100 < freq) and not any? turtles-on patch x y [
create-cars 1 [
setxy x y
set heading head
set color one-of base-colors
]
]
end
to make-new-carSE [freq x y head ]
if (random-float 100 < freq) and not any? turtles-on patch x y [
create-carsSE 1 [
setxy x y
set heading head
set color one-of base-colors
]
]
end
并且通过重复相同的过程只是使用不同的品种名称而成为 冗余 我想做类似 this 的事情(将品种名称作为参数并将其与 create 一起使用- 命令):
to make-new-car [freq x y head breed-name]
if (random-float 100 < freq) and not any? turtles-on patch x y [
create-breed-name 1 [
setxy x y
set heading head
set color one-of base-colors
]
]
end
然而 Netlogo 提示 create-breed-name
没有定义。有什么想法吗?
最佳答案
执行此操作的最简单方法是执行 create-turtles
然后 set品种品种名称
。这是一个例子。
breed [ testers tester ]
to make-turtles [ breed-name ]
create-turtles 1 [ set breed breed-name ]
end
to setup
make-turtles testers
end
您也可以在构造适当的字符串后使用 run
做一些事情,但我认为上面更简单。
关于netlogo - 我可以用变量修改 NetLogo 命令吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43541754/