Hi Vidushi,
I am including below some code that I think will be helpful.
I think you need to think through some of what you are doing (unless you have implemented it code you didn’t show)
In particular as you have it set up potential-target? is a patch variable, so my-target will always be the same agent-set, and rich-target will always be one of the patches that has the highest value of richness.
Here are a few more suggestions:
You seem to be using an older syntax for anonymous functions. Maybe you copied a old example.
I'd recommend downloading and installing NetLogo 6.2.0, our most recent version
and that you look commands up in the corresponding NetLogo Dictionary
I think you should pay attention to the differences between lists and agentsets, and which are acceptable as input or output for a given command.
Some commands operate on both, but some do not. Note that when you sort an agent set you get a list.
The NetLogo Programming Guide is a good place to turn for concepts such as lists and agentsets.
Here is some code that does what I think you are trying to do.
patches-own [ potential-target? richness ]
turtles-own [ my-target closest-target rich-target ]
to setup
clear-all
create-turtles 5 [fd random 10]
ask patches [ set richness random 100 set potential-target? one-of [true false]]
end
to go
ask turtles [ pick-target
type "closest patch" show closest-target
type "richness " show [richness] of rich-target
type "richest patch" show rich-target
rt ( random 60) - 30 fd 1 ]
end
to pick-target
set my-target ( patches with [ potential-target? = true ])
set closest-target max-one-of my-target [ distance myself]
set rich-target max-one-of my-target [ richness]
end
Aaron
--
Aaron Brandes, Software Developer
Center for Connected Learning and Computer-Based Modeling
--
You received this message because you are subscribed to the Google Groups "netlogo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
netlogo-user...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/netlogo-users/342601fe-dd28-4a2a-ae61-e466dde793c3n%40googlegroups.com.