Pencil Code Reference > getxy

 

getxy getting an object's position

getxy() returns the position of an object.

Syntax

jim.getxy()

The position will be the array [x, y], representing the x and y coordinates of the object.

Click the example below to see the turtle's position.

Because getxy() returns an array, it is very easy to get either the x or y coordinate without getting the other as well.

The following example will only return the x value because of getxy()[0]. getxy()[1] would return the y value.

p = write ''
forever ->
  x = getxy()[0]
  p.text "x =" + x
click (e) ->
  moveto e