问题
Is there a built in function that will ask up to n-of turtles? So if you ask 50 turtles but there are only 40 it will ask those 40 and move on. Or there aren't any, it will just move on.
Alternatively does anyone have any neat code for achieving this?
回答1:
This will pick out 40 random turtles:
ask n-of 40 turtles [ <whatever you want them to do> ]
If you want to pick out a smaller number when there are not 40 available, you could do something like:
let num min (list 40 count turtles)
ask n-of num turtles [ <whatever you want them to do> ]
来源:https://stackoverflow.com/questions/35697025/ask-up-to-n-of-turtles