user2855913
user2855913

Reputation: 53

How can I find out which turtle is at a particular coordinate in netlogo

How can I find out the Id of a turtle by the co-ordinate it is at some instant. i.e if some turtle is at (a,b) which is known but I don't know which one then how do I find it.

Upvotes: 0

Views: 241

Answers (2)

Alan
Alan

Reputation: 9620

Assuming any turtle on the patch will do (or, if there is only one per patch):

to-report who-at-xy [#x #y]
  let _candidates [turtles-here] of patch #x #y
  if (any? _candidates) [
    report [who] of one-of _candidates
  ]
  report -1
end

That said, you almost surely should be working with turtles directly rather than with their who numbers.

Upvotes: 0

JenB
JenB

Reputation: 17678

you could do something like:

let my-turtle one-of turtles with [xcor = a and ycor = b]
ask my-turtle [ whatever you want it to do ]

But turtle coordinates are floating point. So you shouldn't really be trying to check whether the value is equal to some number.

How do you know it is at (a,b)? If it's because it satisfied some condition and moved there, then why don't you label it as the one you want when it satisfies the condition for example?

Upvotes: 1

Related Questions