当 <breed> 作为参数或 netlogo 函数中的参数传递时,如何调用 <breed>-here 过程?

how do I call <breed>-here procedure when <breed> is to be passed as an argument or a parameter within a function in netlogo?

当它作为参数传递给另一个函数时,如何为 <breed>-here 指定品种名称?我目前收到语法错误:

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

编辑:

谢谢,grow3 工作得很好。

问题 2:

具有特殊属性的海龟有点复杂,我如何在 args 中传递它?例如:

ask monomers1 with [ aggregated = false ]

而不仅仅是

ask monomers1 

作为第一个参数?

问题 3:

此外,如何传递必须孵化的品种参数?

像这样

hatch-<breed> 1

但该品种作为参数传递为#hatching-species

hatch-#hatching-species 1

这里有两个选项。我不认为这两个都很好,但如果我正在写它,我会选择 grow2,因为除非你真的必须,否则你通常不想在字符串上使用 runresult .

grow1 使用 runresult on a string it creates from the breed name, making frogs-here or mice-here. grow2 turns the turtle's breed into a string so it can compare to the breed name in a with clause. Both are using word to make the string.

编辑添加:前两个选项假定您传递的品种是一个字符串值。如果你从另一只海龟那里得到一个实际的品种值,也许通过做类似 [breed] of my-turtle 的事情,你可以修改 grow2 以接受品种并删除 word 东西。我把它写成 grow3

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