Javier Sandoval
Javier Sandoval

Reputation: 507

Show patch coordinates in Netlogo

I'm using the following code at the command center to show the coordinates of a random patch:

ask one-of patches [show pycor pxcor]

but I get an Expected command error, how can I fix it?

Upvotes: 0

Views: 746

Answers (2)

Matteo
Matteo

Reputation: 2926

show takes only one input, so you need the patch to perform two separate actions. ask one-of patches [show pycor show pxcor] will print both coordinates:

observer> ask one-of patches [show pycor show pxcor]
(patch -9 10): 10
(patch -9 10): -9

If for some reason you don't like the fact that this results in the output being shown on two lines, you can use word and have it reported as a single string: ask one-of patches [show (word pycor " " pxcor)]:

observer> ask one-of patches [show (word pycor " " pxcor)]
(patch -9 4): "4 -9"

Edit Using a list, as in Luke's answer, looks certainly more elegant than using a string with manually-inserted spaces... what a dumb choice lol

Upvotes: 1

Luke C
Luke C

Reputation: 10336

show takes a single argument, and you are passing it two- pxcor and pycor. It depends how you want to display this, but depending on your goal you could do:

observer> ask one-of patches [show pycor show pxcor]
(patch -15 0): 0
(patch -15 0): -15

Or more likely

observer> ask one-of patches [show list pycor pxcor ]
(patch 16 8): [8 16]

Upvotes: 2

Related Questions