Create new turtles (synchronous constructor)
(newturtles n)
newturtles n [instructions]
(newturtles n [instructions] expression1 expression2 ...)
newturtles n function
(newturtles n function expression1 expression2 ...)
Creates n new turtles simultaneously. A list of instructions or a function passed as
an argument is used as constructor of each new turtle. Constructors are executed in parallel. The turtle
which called anewturtles
instruction is waiting for the
constructors completion. The constructor's arguments can be passed as optional expressions (all new
turtles use the same argument values).
Example 1:
"t := (newturtles 3)
print who
print children
foreach "ti :t [(print who @ :ti parent @ :ti )]
Output:
first
[t1 t2 t3]
t1 first
t2 first
t3 first
Example 2:
"t := newturtles 3 [
"x := random 10
print who
]
foreach "ti :t [print :x @ :ti]
Output:
t1
t2
t3
2
5
3
Example 3:
to model :dt
repeat 3 [print who wait :dt]
"x := :dt
end
"t := (newturtles 2 $model 50)
foreach "ti :t [print :x @ :ti]
Output:
model1
model2
model1
model2
model1
model2
50
50
See also:
Turtle - object
Table of Content