具有来自同名的两个不同品种的海龟特定变量
Having turtle-specific variables from two different breeds of the same name
我有一个简短的问题。
假设我想要两个品种,定义为
繁殖[人类人类]
繁殖[蚊子蚊子]
并希望为这些品种设置同名 的海龟特定变量 。所以
humans-own
[
infected
]
mosquitoes-own
[
infected
]
我想稍后调用该过程(假设已经进行了设置,将 infected 设置为初始布尔值 false),例如
to infect
set infected true
end
。我知道它会调用 set both mosquito and human-specific 'infected' variables to be true,但如果我想这样做怎么办:
to specific-infect
if turtles = humans
[
set infected true
]
if turtles = mosquitoes
[
set infected true
]
end
。它会检查乌龟是否是人类,如果是,则将人类特定的 'infected' 设置为 true,或者两者都做?本质上,我要问的是,您能否拥有同名的特定于乌龟的变量,并使其在代码中可行?
品种当然可以有 "own" 个具有相同名称的变量,但与一般海龟一样,基本上只有一个品种可以更改其变量之一的值,并且您需要要求它这样做。因此,如果您想将所有人类的感染设置为 true,而所有蚊子的感染设置为 false,您可以按如下方式进行:
ask humans [set infected true]
ask mosquitoes [set infected false]
或者,仅针对某些人
ask humans with [some characteristic] [set infected true]
同样,您可以让品种中的代理人各自报告其变量的值。
show [infected] of human with [some characteristic]
查看 NetLogo 基元 ask
、of
和 with
以获取一些示例。
在海龟个体层面,海龟 'knows' 自己的品种。所以你可以添加
if breed = humans [do human infection thing]
if breed = musquitos [do musquito infection thing]
我有一个简短的问题。
假设我想要两个品种,定义为 繁殖[人类人类] 繁殖[蚊子蚊子] 并希望为这些品种设置同名 的海龟特定变量 。所以
humans-own
[
infected
]
mosquitoes-own
[
infected
]
我想稍后调用该过程(假设已经进行了设置,将 infected 设置为初始布尔值 false),例如
to infect
set infected true
end
。我知道它会调用 set both mosquito and human-specific 'infected' variables to be true,但如果我想这样做怎么办:
to specific-infect
if turtles = humans
[
set infected true
]
if turtles = mosquitoes
[
set infected true
]
end
。它会检查乌龟是否是人类,如果是,则将人类特定的 'infected' 设置为 true,或者两者都做?本质上,我要问的是,您能否拥有同名的特定于乌龟的变量,并使其在代码中可行?
品种当然可以有 "own" 个具有相同名称的变量,但与一般海龟一样,基本上只有一个品种可以更改其变量之一的值,并且您需要要求它这样做。因此,如果您想将所有人类的感染设置为 true,而所有蚊子的感染设置为 false,您可以按如下方式进行:
ask humans [set infected true]
ask mosquitoes [set infected false]
或者,仅针对某些人
ask humans with [some characteristic] [set infected true]
同样,您可以让品种中的代理人各自报告其变量的值。
show [infected] of human with [some characteristic]
查看 NetLogo 基元 ask
、of
和 with
以获取一些示例。
在海龟个体层面,海龟 'knows' 自己的品种。所以你可以添加
if breed = humans [do human infection thing]
if breed = musquitos [do musquito infection thing]