The turtle sets its x-coordinate to x and its y-coordinate to y.
Equivalent to set xcor x set ycor y, except it happens in one time step instead of two.
If x or y is outside the world, NetLogo will throw a runtime error.
setxy 0 0
;; turtle moves to the middle of the center patch
setxy random-xcor random-ycor
;; turtle moves to a random point
setxy random-pxcor random-pycor
;; turtle moves to the center of a random patch
The specified agent or agentset runs the given commands.
ask turtles [ fd 1 ]Note: only the observer can ask all turtles or all patches. This prevents you from inadvertently having all turtles ask all turtles or all patches ask all patches, which is a common mistake to make if you're not careful about which agents will run the code you are writing.
Note: Only the agents that are in the agentset at the time the
ask begins run the commands.
Kills all turtles.
Also resets the who numbering, so the next turtle created will be
turtle 0.
The turtle or link dies.
if xcor > 20 [ die ]
;; all turtles with xcor greater than 20 die
ask links with [color = blue] [ die ]
Creates number new turtles at the origin. New turtles have random integer headings and the color is randomly selected from the 14 primary colors.
If the create-<breeds> form is used, the new turtles are created as members of the given breed.
If commands are supplied, the new turtles immediately run them. This is useful for giving the new turtles a different color, heading, or whatever. (The new turtles are created all at once then run one at a time, in random order.)
crt 100 [ fd 10 ] ;; makes a randomly spaced circle
;; all the blue links will die
Prints value in the Command Center, preceded by the calling agent, and followed by a carriage return. (The calling agent is included to help you keep track of what agents are producing which lines of output.) Also, all strings have their quotes included similar to write.
set-default-shape
Specifies a default initial shape for all turtles, or for a particular breed. When a turtle is created, or it changes breeds, it shape is set to the given shape.
This command doesn't affect existing turtles, only turtles you create afterwards.
The specified breed must be either turtles or a breed defined by the breed keyword, and the specified string must be the name of a currently defined shape.
In new models, the default shape for all turtles is "default".
Note that specifying a default shape does not prevent you from changing an individual turtle's shape later; turtles don't have to be stuck with their breed's default shape.
create-turtles 1Advances the tick counter by number. The input may be an integer or a floating point number. (Some models divide ticks more finely than by ones.) The input may not be negative.
See also tick, ticks, reset-ticks.
From an agentset, reports an agentset of size size randomly chosen from the input set, with no repeats.
From a list, reports a list of size size randomly chosen from the input set, with no repeats. The items in the result appear in the same order that they appeared in the input list. (If you want them in random order, use shuffle on the result.)
It is an error for size to be greater than the size of the input.
ask n-of 50 patches [ set pcolor green ]
;; 50 randomly chosen patches turn green
Resets the tick counter to zero.
See also tick,
ticks,
tick-advance.
Reporter must report a boolean (true or false) value.
If condition reports true, runs commands.
The reporter may report a different value for different agents, so some agents may run commands and others don't.
if xcor > 0[ set color blue ]
;; turtles in the right half of the world
;; turn blue
Reporter must report a boolean (true or false) value.
If reporter reports true, runs commands1.
If reporter reports false, runs commands2.
The reporter may report a different value for different agents, so some agents may run commands1 while others run commands2.
ask patches
[ ifelse pxcor > 0
[ set pcolor blue ]
[ set pcolor red ] ]
;; the left half of the world turns red and
;; the right half turns blue
See also if,
ifelse-value.
patch-here reports the patch under the turtle.
Note that this reporter isn't available to a patch because a patch
can just say "self".
Set the caller's heading towards agent.
If wrapping is allowed by the topology and the wrapped distance (around the edges of the world) is shorter, face will use the wrapped path.
If the caller and the agent are at the exact same position, the
caller's heading won't change.
Set the caller's heading towards the point (x,y).
If wrapping is allowed by the topology and the wrapped distance (around the edges of the world) is shorter and wrapping is allowed, facexy will use the wrapped path.
If the caller is on the point (x,y), the caller's heading won't
change.
If number is positive, reports a random integer greater than or equal to 0, but strictly less than number.
If number is negative, reports a random integer less than or equal to 0, but strictly greater than number.
If number is zero, the result is always 0 as well.
Note: In versions of NetLogo prior to version 2.0, this primitive reported a floating point number if given a non-integer input. This is no longer the case. If you want a floating point answer, you must now use random-float instead.
show random 3
;; prints 0, 1, or 2
show random -3
;; prints 0, -1, or -2
show random 3.5
;; prints 0, 1, 2, or 3