I don't understand your total problem but I think the "sort-on" command
will help. This sorts an agent-set on some property of the agent set and
produces a sorted list. Then you can pull off the last item of the list as
the maximum item.
Here's code:
;;==========================================
patches-own [ x ]
to setup
clear-all
let maxval -100;
let maxpatch "";
;;========== set up a problem and peek at the answer ====
ask patches [
set x random 100;
if ( x > maxval) [
set maxval x
set maxpatch self]
]
print ( word "maxval should be " maxval " for patch " maxpatch)
;;================= end problem setup
;; now solve it using "sort-on"
let mylist sort-on [x] patches
set maxpatch last mylist
ask maxpatch [ print (word self " has x value " x ) ]
reset-ticks
end