Create new objects (synchronous constructor)

(newobjects n)
newobjects n [instructions]
(newobjects n [instructions] expression1 expression2 ...)
newobjects n function
(newobjects n function expression1 expression2 ...)

Creates n new objects simultaneously. A list of instructions or a function passed as an argument is used as constructor of each new object. Constructors are executed in parallel. The turtle/object which called anewobjects instruction is waiting for the constructors completion. The constructor's arguments can be passed as optional expressions (all new objects use the same argument values).

Object in POOL is a simplified version of a turtle. Objects do not have graphics representation and do not handle events related to graphics (e.g. mouse clicks). Objects use less memory, they are created faster and also execute their tasks faster than turtles.

Example 1:

"t := (newobjects 3)
print who
print children
foreach "ti :t [(print who @ :ti parent @ :ti )]

Output:

first
[o1 o2 o3]
o1 first
o2 first
o3 first

Example 2:

"t := newobjects 3 [
  "x := random 10
  print who
]
foreach "ti :t [print :x @ :ti]

Output:

o1
o2
o3
2
5
3

Example 3:

to model :dt
  repeat 3 [print who wait :dt]
  "x := :dt ;global variable (public)
end

"t := (newobjects 2 $model 50)
foreach "ti :t [print :x @ :ti]

Output:

model1
model2
model1
model2
model1
model2
50
50

See also:

Turtle - object
Synchronization of multiple objects

Table of Content