After a short while I get a typical error message when running my netlogo model:
DISTANCE expected input to be an agent but got NOBODY instead. error while human 18 running DISTANCE
So far, I was not able to fix the mistake. Netlogo shows me the location in the source code where the mistake occurs:
let dist-nearest-resource distance nearest-resource
I believe to know that the message means that there are no green patches available to go to. I do know what else to code other than to say that the agents should move on and walk randomly around.
Here, down below is my minimal model to make you better understand. Does somebody know how to fix this?
breed [ humans human ]
humans-own [ energy ]
patches-own [ countdown ]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to setup
ca
create-humans(population)
[
set shape "person"
setxy random-xcor random-ycor
]
ask patches [
set pcolor one-of [green brown]
ifelse pcolor = green
[ set countdown 30 ]
[ set countdown random 30 ]
]
reset-ticks
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go-people
ask humans [ orientation ]
end
to orientation
ifelse (energy < 4) [ ;if hungry
let nearest-resource min-one-of (patches with [pcolor = green] in-cone 3 360 ) [ distance myself ] ;check distance between you and nearest resource (3 fields 360 degrees view)
let dist-nearest-resource distance nearest-resource ;defines what is the shortest distance
if is-patch? nearest-resource [ ;if green patch exist at all
face nearest-resource fd distance nearest-resource ;face it and go directly to it
]
]
[ walk ] ;otherwise just walk randomly around
end
to walk
ask humans [
rt random-float 30 - random-float 30 ;randomly wandering around
if patch-at dx 0 = nobody [ ;humans get "bounced" away from the limits of the world
set heading (- heading) ]
if patch-at 0 dy = nobody [
set heading (180 - heading) ]
]
end
to sustainability ;countdown on brown patches: if 0 is reached, grow resources again after the time set by user
if pcolor = brown [
ifelse countdown <= 0
[ set pcolor green
set countdown regrowth-time ] ;exhausted fields need 30 ticks to recover
[ set countdown countdown - 1 ]
]
end
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
to go
if not any? turtles [ stop ] ;defensive programming
go-people
ask patches [ sustainability ]
set resources count patches with [pcolor = green]
tick
if count patches with [pcolor = green] = 0 [ stop ] ;model stops if food is no longer available
if count turtles = 0 [ stop ] ;model stops if all humans died
end