Use tasks:
turtles-own [noise]
to setup
...
ask cats [ set noise task meow ]
ask dogs [ set noise task bark ]
...
end
to go
...
ask turtles [ run noise ]
...
end
Question
Suppose we have two breeds, cats
and dogs
. On go
, we want cats
to meow
and dogs
to bark
. ask
causes the agents in the given agentset to run the code block in a random order, which is great. However, if we do:
to go
ask cats [ meow ]
ask dogs [ bark ]
tick
end
dogs
always go after cats
. We could solve this problem with conditionals:
to go
ask turtles [
if breed = cats [ meow ]
if breed = dogs [ bark ]
]
tick
end
but this is gross (note that you can replace the turtles
with (turtle-set cats dogs)
for more complicated situations with breeds that you don't want mixed in). Any better solutions?
Solution
Use tasks:
turtles-own [noise]
to setup
...
ask cats [ set noise task meow ]
ask dogs [ set noise task bark ]
...
end
to go
...
ask turtles [ run noise ]
...
end
OTHER TIPS
How about a shuffled list of paired agentsets and tasks?
to go
let actions (list
(list cats task meow)
(list dogs task bark)
)
foreach shuffle actions [
ask first ? [ run last ? ]
]
end