How to get connected two or more turtles within radius NetLogo

614 views Asked by At

I have more turtles moving in the world, i would like to get them connected when they are inside an area (circles).

This is an example:

enter image description here

I was trying with a function like this, called in the "go" procedure (tick advanced) but this doesn't work. Any suggestion?

to connect
ask turtles in-radius radius [
  create-link-from myself
  create-link-to myself
]
end
1

There are 1 answers

2
JenB On BEST ANSWER

If I have understood what you want, this will work

globals [radius]

to setup
  clear-all
  create-turtles 50 [setxy random-xcor random-ycor]
  set radius 5
  connect
end

to connect
  ask turtles
  [ ask other turtles in-radius radius
    [ create-link-from myself
    ]
  ]
end

The problem is that you have ask turtles in-radius ... but you don't specify the reference point. That is, within a certain distance of what? In my code, I ask each turtle to become the reference point and then ask the turtles within distance of itself to do the linking.