lsroudi
lsroudi

Reputation: 81

Netlogo how turtles move others objects

I have two kind of turtles :

The objective is that the car should find and grasp 3 objects and move them to the center. I tried to make link between turtle and object but I guess is a wrong idea.

My code so far:

to move-turtles
  ask car [
    right random 360
    forward 1
    ask other object-here [
      set color red
      create-links-to car 
      ]
  ]
end

I'm struggling with how the car can grasp and move objects.

Upvotes: 2

Views: 307

Answers (1)

JenB
JenB

Reputation: 17678

You can use the tie attribute of a link to make them move together. I have also done some code cleaning - if cars and objects are different breeds with singular car and object respectively, you don't need other, but you do need objects rather than object or you will get a syntax error (<breeds>-here).

In theory, the following code will randomly pick a car, move it one patch, create links with the objects there, then move 5 with those objects. However, it is not tested.

to move-turtles
  ask one-of cars [
    let thiscar self
    right random 360
    forward 1
    ask objects-here [
      set color red
      create-links-from thiscar [tie] 
    ]
  ]
  fd 5
end

Fixed to take into account the errors spotted by Seth!

Upvotes: 2

Related Questions