I am attempting to iterate over a set of turtles and assign each of them a different, random speed. When I attempt to use:foreach turtles [ ... ]
I get an error message stating "cannot iterate over agentset". I know I can use ask
for setting all turtles the same, but I want to have turtles moving at different speeds from one another.
Asked
Active
Viewed 3,734 times
2

bubbalouie
- 643
- 3
- 10
- 18
-
Instead of cycles, you need to think this as a set operation. You ask the set to do something. Also, using cycles has a performance penalty on your models. – Edmundo Apr 05 '16 at 22:46
1 Answers
7
ask
can do this job just fine:
ask turtles [
set speed random 10
]
this will give each turtle its own different, random speed.

Seth Tisue
- 29,985
- 11
- 82
- 149
-
just in case you want to have the turtle itself inside the block, use "self". [Link to the documentation](http://ccl.northwestern.edu/netlogo/docs/dict/self.html). – Khalil Youssefi Feb 01 '21 at 21:55
-
This only works for random setting.. How do you set incrementing values to all turtles? eg. If I want 10 turtles with speeds from 1 to 10? – Colin R. Turner Mar 10 '21 at 18:43
-
@freeworlder Not sure what you mean. Consider opening a new question and explaining what you mean in more detail – Seth Tisue Mar 11 '21 at 20:54
-
@SethTisue I meant 1,2,3,4... etc. I did it using a while loop. – Colin R. Turner Mar 13 '21 at 12:14