我如何称呼<;品种>-当<;品种>;是否作为参数或参数在netlogo中的函数中传递?
当它作为一个参数传递给另一个函数时,如何为我如何称呼<;品种>-当<;品种>;是否作为参数或参数在netlogo中的函数中传递?,netlogo,Netlogo,当它作为一个参数传递给另一个函数时,如何为-此处指定品种名称?我当前收到一个语法错误: to fwd-reaction [ #asking-species species2 #x-k_on #x-alpha #species-to-die #new-breed ] ask #asking-species [ if (any? other species2-here ) and random-float 1000 < (#x-k_on * 2 * #x-alpha)
-此处指定品种名称?我当前收到一个语法错误:
to fwd-reaction [ #asking-species species2 #x-k_on #x-alpha #species-to-die #new-breed ]
ask #asking-species [
if (any? other species2-here ) and random-float 1000 < (#x-k_on * 2 * #x-alpha)
[
ask one-of other #species-to-die -here
[ die ]
set breed #new-breed
set-attributes2 0 2 self true false red
]
]
end
而不仅仅是
ask monomers1
作为第一个arg
问题3:
另外,我如何通过一个必须孵化的品种的争论
像这样
hatch-<breed> 1
这里有两个选择。我认为这两种方法都不太好,但如果我在编写它,我会选择grow2
,因为除非您真的必须这样做,否则您通常不想在字符串上使用runresult
grow1
使用它从品种名称创建,在这里制作青蛙
或老鼠
grow2
将海龟的品种转换为字符串,以便与中的品种名称进行比较。两者都在使用
编辑添加:前两个选项假设您传递的品种是字符串值。如果你从另一只乌龟那里得到了一个实际的品种值,也许通过对我的乌龟进行[breed]之类的操作
你可以修改growt2
以接受该品种,并删除单词
内容。我认为这是growt3
breed [ mice mouse ]
breed [ frogs frog ]
to setup
clear-all
create-mice 100 [ fd 100 set color grey ]
create-frogs 100 [ fd 100 set color green ]
ask n-of 100 patches [ grow1 "mice" ]
ask n-of 100 patches [ grow2 "frogs" ]
let mice-breed [breed] of one-of mice
ask n-of 100 patches [ grow3 mice-breed ]
end
to grow1 [breed-name]
let breed-here (runresult (word breed-name "-here"))
if any? breed-here [
ask one-of breed-here [
set size (size + 1)
]
]
end
to grow2 [breed-name]
let breed-here turtles-here with [(word breed) = breed-name]
if any? breed-here [
ask one-of breed-here [
set size (size + 1)
]
]
end
to grow3 [breed-val]
let breed-here turtles-here with [breed = breed-val]
if any? breed-here [
ask one-of breed-here [
set size (size + 1)
]
]
end
谢谢你,grow3做得很好。我编辑了我的原始问题,问了另一个与此相关的问题。有一个特殊属性的海龟有点复杂,我如何在args中传递它?例如:使用[aggregated=false]询问monomers1,而不是仅询问monomers1作为第一个参数?@bigbiodata通常在StackOverflow上,您应该始终提出新问题,而不是在细化中编辑。
hatch-#hatching-species 1
breed [ mice mouse ]
breed [ frogs frog ]
to setup
clear-all
create-mice 100 [ fd 100 set color grey ]
create-frogs 100 [ fd 100 set color green ]
ask n-of 100 patches [ grow1 "mice" ]
ask n-of 100 patches [ grow2 "frogs" ]
let mice-breed [breed] of one-of mice
ask n-of 100 patches [ grow3 mice-breed ]
end
to grow1 [breed-name]
let breed-here (runresult (word breed-name "-here"))
if any? breed-here [
ask one-of breed-here [
set size (size + 1)
]
]
end
to grow2 [breed-name]
let breed-here turtles-here with [(word breed) = breed-name]
if any? breed-here [
ask one-of breed-here [
set size (size + 1)
]
]
end
to grow3 [breed-val]
let breed-here turtles-here with [breed = breed-val]
if any? breed-here [
ask one-of breed-here [
set size (size + 1)
]
]
end