Home > database >  Add variables from two breeds Netlogo
Add variables from two breeds Netlogo

Time:11-17

I'm trying to intoxicate bees by being near the flower. Toxicity is a flower-own variable, however, I want to add the number of said toxicity to the established mortality for the bees. I get the error that toxicity is not a bees variable, which is true, but how do I add this. The idea is that the flower has a set toxicity and if someone is near it gets intoxicated making them die faster. Thanks in advance, the code should work copy past.

breed [flowers flower]
breed [bees bee]

turtles-own
[
  
  mortality
  tipo_exposicion
  t_supervivencia
]
flowers-own [toxicity]


to setup
  clear-all
  
  create-flowers 5
  [
    set shape "flower"
    set color red
    set size 4
     move-to one-of patches
  ]

  ask patches [set pcolor 63]
create-bees 100
   [
    setxy random-xcor random-ycor
    ]
  ask bees
  [
    set shape "person"
    set size 1
    set color yellow
  set t_supervivencia 0
  ]

ask flowers [set color gray]
 reset-ticks
end

to go
  
  ask bees [ 
  move-bees
    ]
   ask bees[intoxicarse]
  ask flowers [  morir_bees_eating]
  
  tick
end

to move-bees
      right random 60
    forward 1
    set t_supervivencia t_supervivencia   1
    set mortality mortality   1
end 
 
to intoxicarse
  ask bees in-radius 10 [if any? flowers with [color = gray][
     set mortality mortality   toxicity]]
  
end
 to morir_bees_eating
    
    if  color = gray [set toxicity  34]
end

CodePudding user response:

Let me first "translate" what the intoxicarse procedure is doing right now:

It is called for any bee. So lets say first it calls the procedure on bee 1. Then, it looks for bees within a radius of 10 (ask bees in-radius 10). For every close bee, it will search in the set of all flowers (not just the close ones) if there are any gray ones. If there are any flowers in the world with gray color, all bees that are close to bee 1 would increase their mortality.

Here's a suggestion on how you could change your code:

  1. create an agentset with let, that contains all close flowers with gray color. You can combine in-radius and with.
  2. if there are close flowers (any?) then you can get their toxicity with of. One point, that isn't clear to me is, what happens, when there are more than one close flower. Should their toxicity sum up? Or should only one of the close flowers intoxicate the bee? You can use sum or one-of.
  let close_flowers flowers in-radius 10 with [color = gray]
  if any? close_flowers
  [
    let this_toxicity [toxicity] of one-of close_flowers ;get toxicity from one close flower
    let this_toxicity sum [toxicity] of close_flowers ;sum of toxicity
    set mortality mortality   this_toxicity
  ] 

CodePudding user response:

I would have the flowers call intoxicarse and write it more simply as

to intoxicarse
  ask bees in-radius 10 [set mortality mortality   toxicity]
end
  • Related