This is one of the more confusing parts of NetLogo. You don’t need to use myself here you can just do
to move-turtles
ask turtles [
set rad effort
ask patches in-radius rad [ ; (of course you could just use `in-radius effort` here)
set yum max-one-of patches [presource]
]
...
end
myself is used to refer to the asker agent when agents ask other agents to do things. For example if you had two types of turtles called sheep and goats
ask sheep [
ask one-of goats [
set xcor [effort] of myself
]
]
That would have each sheep ask one goat to set its xcor to the effort value of the sheep that asked it to do that.
That is the FIRST thing I tried, and got the error (in the statement:set dxx [pxcor] of yum - xcor):
OF expected input to be a turtle agentset or patch agentset or turtle or patch but got the number 0 instead.
error while turtle 6 running OF
called by procedure MOVE-TURTLES
called by procedure GO
called by Button ‘go’
I had to initialize it: set yum self in setup-patches.
Can you please tell me why my turtles jump more than is possible with the variable effort (currently set effort random-float 3 in setup-turtles)?
Currently I have:
to move-turtles
ask turtles [
ask patches in-radius effort[
set yum max-one-of patches [presource] ;;the patch with the largest resource
]
set dxx [pxcor] of yum - xcor
set dyy [pycor] of yum - ycor
ifelse dxx = 0 AND dyy = 0 ;; stay in place if patch is already the highest resource
[
set dist 0
]
[set heading atan dxx dyy
set dist sqrt ( dxx * dxx + dyy * dyy) ;;
jump dist] ;;go to patch with largest resource
That should do what you want (move to the patch with the largest resource within the radius effort including if that patch is the one the turtle is currently on).