Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+9 votes

I want to provide each turtle each different variable like different x and y (turtles-own). For example, I plan to give each turtle to run different circle base on their location. But when I use the command "ask turtles", all of the turtles tend to share the same variables and only run one circle.

asked in CSC 150 January201920 by (1 point)
+2

I agree with Yadel, look on the S-drive and there should be a template on how to code a breed. If you cannot find it let me know and I can send you the code example over this!

+1

There's also a "Breeds and Shapes" example under File -> Models Library -> Code Examples

2 Answers

+4 votes

you should probably set a breed for it and then you can create all your other turtles at a random location however you can create make any turtles in this breed appear at a set point.
you can also use the random command to set the turtles locations and then you can make a circle

answered by (1 point)
0

This works. Thank you

+2 votes

Perhaps something like this?

to setup
    cro 20
    ask turtles [
        forward 0.1
        right who     ;; who refers the the turtle's ID # (0, 1, 2, ...)
    ]
 end

Alternatively, you can give each turtle a property (turtles-own variable), and give it a random value, so each turtle behaves differently. Something like this:

turtles-own [ turning-angle ]

to setup
    cro 20 [
        set turning-angle random 30
    ]
 end

to go  
   ask turtles [
      forward 0.1
      right turning-angle
   ]
end
answered by (5.7k points)
+1

Thank you

...