Reputation: 29
I want to model agents moving around, and dying if they reach a patch that already has a # of agents above the carrying capacity (which is determined by a slider). I tried writting it like this:
to check-if-dead
if habitat = "escarabajo" [
ask escarabajos [
if pcolor = one-of [yellow lime orange grey blue ] [die]
if escarabajos-on patch-here >= capacidad-de-carga-bosques [die]
]
]
but I get a message highlighting "escarabajos-on patch-here",and saying > >= expected this input to be an agent or number or string, but got a turtle agentset instead >
Upvotes: 0
Views: 35
Reputation: 14972
The result of escarabajos-on patch-here
is an agentset: the set of all escarabajos
on the current patch. What you want is the number of escarabajos
on the current patch, so you need to count
them:
if count escarabajos-on patch-here >= capacidad-de-carga-bosques
That being said, escarabajos-on patch-here
is needlessly verbose, since NetLogo also has a <breeds>-here
primitive:
if count escarabajos-here >= capacidad-de-carga-bosques
Finally, I have a hunch that you meant:
if member? pcolor [ yellow lime orange grey blue ]
instead of:
if pcolor = one-of [yellow lime orange grey blue ]
The one-of
primitive picks an element from a list at random, so your condition would have been true only if the randomly picked color happened to be the color of the current patch. By using member?
instead, the condition will be true if the color of the patch is any member of the list.
Upvotes: 1