Dan
Dan

Reputation: 11

Make a list of distances from turtle to patches in Netlogo

I'm trying to ask turtles called "mosqs" to create a list of the distances to the patches within particular radius of them so that I can eventually use that info in a probabilistic function. However, I can't seem to figure the distance part out. First, I create a variable called "nearby" that identifies the patches within a radius of an agent set. Next, I create lists of both the x and y coordinates. My latest approach has been to try to create a list called "dist" that asks the patches within the agentset to print out their distances from the location of the turtle ("self"). The code below gives me the "Expected reporter" error and I'm not sure why. I've tried various things as well, such as using the x and y coordinate lists with the distancexy command, but I just can't seem to get it to work. Any suggestions?

Thanks,

Dan

ask mosqs [ 

let nearby patch-set patches in-radius 2 
let xs [pxcor] of nearby  
let ys [pycor] of nearby 
let dist (list (ask nearby[ print distance self]))

Upvotes: 1

Views: 1101

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30508

This should work:

ask mosqs [
  let nearby patches in-radius 2
  let dist [distance myself] of nearby
]

Note that patches in-radius 2 is already a patch set, so you don't need to call patch-set on it.

Note the use of myself to refer back to the calling turtle. (distance self can't be right, because distance self is invariably 0.)

I don't see any need to use pxcor and pycor here.

Upvotes: 3

Related Questions