bksnlow
bksnlow

Reputation: 137

Netlogo: How to make a turtle check for variables in a radius

I want the turtles to check in a radius of 2 if the temperature of a patch is within the acceptable range that the turtle have, if it is then he would move there, if not then get out of the patch/dont go there. Any guidance will be appreciated and if any more info is needed please let me know.

Ive seen some questiones here but they seem to complex and i dont fully understand.

Thanks.

turtles-own [energia]
;La tierra tiene tres estados, borde abandono y bosque. Cada estado tiene sus valores de temperatura, humedad relativa y dosel 
patches-own  
[bordear
abandono
reforestado
potrerizado
temperatura
humedad
dosel
]
breed [ potreros potrero ] 
to setup
  clear-all
;Se segmenta el mundo en potrero, borde y bosque. Se ponen colores para diferenciarlos 
  ask patches with [
    pxcor <= 30 and
    pxcor >= min-pxcor and
    pycor <= 60 and
    pycor >= min-pycor ] [
    set pcolor 35
    set temperatura 28
  ]
 create-potreros 50

  [ set size 3        ;; easier to see
    set color yellow
setxy random xcor random ycor
move-to one-of patches with [pcolor = 35]
    set energia 100
 ] 
end
to go
  ask potreros [
    ;if energia < 10 [descansar-potrero]
    if energia >= 10 and energia <= 70 [move-potrero]]
end
to move-potrero
    ask turtles in-radius 2 [if temperatura >= 27 + random  1 [ 
      lt random-float 360
      fd 1]  
  ]
   set energia energia - 5

end
´´´
This is most of the code, the turtle arent moving.

Upvotes: 0

Views: 200

Answers (1)

Jumboman
Jumboman

Reputation: 541

Here are the proper steps to debug:
-start with 1 turtle
-in the Gui, create watch/plots for the variables you are debugging. for example, plot the energy of turtle 0 to see where this is going wrong.
-once you have that bug figured out, have a look at the with keyword and the agentset documentation. instead of using the ask keyword, you can create an agentset of patches with sufficient temperature using with and choose one of them with one-of and move there.

Upvotes: 2

Related Questions