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

Viewed 55

How do I get to specify the breed name for <breed>-here when this is passed as a parameter to another function? I get a syntax error currently:

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

EDIT:

Thank you, grow3 worked superbly.

Question 2:

There is a slight complication with turtles with a special attribute, how do I pass that within the args? For example:

ask monomers1 with [ aggregated = false ]

instead of just

ask monomers1 

as the first arg?

Question 3:

Also, how do I pass an argument of a breed that has to be hatched?

like so

hatch-<breed> 1

but the breed passed as an argument as #hatching-species

hatch-#hatching-species 1
1 Answers

Here are two options. I don't think either of these are great, but if I were writing it, I'd choose grow2, as you usually don't want to use runresult on a string unless you really have to.

grow1 uses 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.

Edit to add: The first two options assumed the breed you are passing is a string value. If you're getting an actual breed value from another turtle, maybe by doing something like [breed] of my-turtle you could modify grow2 to take in the breed and drop the word stuff. I put that as 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
Related