Difference between revisions of "Printer.getCursorPos"

From ComputerCraft Wiki
Jump to: navigation, search
m (Moved to CAT:LuaCoreFunctions)
m (Expanded)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
 
{{Function
 
{{Function
|name=printer.getCursorPos
+
|name=''printer''.getCursorPos
|returns=The x- and y-position of the printer cursor.
+
|returns={{type|number}} x position of the cursor, {{type|number}} y position of the cursor
|api=peripheral
+
|api=printer
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Gives you the x- and y-position of the printer cursor.
+
|desc=Returns the coordinates of the cursor on the paper, works the same way as [[term.getCursorPos]]().
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Prints the cursor of the printer.
+
|desc=Writes text on the paper and then prints the cursor position.
|code=local a, b = printer.getCursorPos()<br/>print("X: ".. a ..", Y: ".. b)
+
|code= local printer = [[peripheral.wrap]]("left")
|output=X: <x position>, Y: <y position>
+
 +
[[printer.newPage]]()
 +
[[printer.write]]("Hello, World!")
 +
 +
local x, y = printer.getCursorPos()
 +
print("The cursor on the paper is on X: " .. x .. " and Y: " .. y)
 +
 +
[[printer.endPage]]()
 +
|output=The cursor on the paper is on X: 14 and Y: 1
 
}}
 
}}
 
}}
 
}}
  
 
[[Category:Lua_Core_Functions]]
 
[[Category:Lua_Core_Functions]]

Latest revision as of 18:42, 9 April 2014


Grid Redstone.png  Function printer.getCursorPos
Returns the coordinates of the cursor on the paper, works the same way as term.getCursorPos().
Syntax printer.getCursorPos()
Returns number x position of the cursor, number y position of the cursor
Part of ComputerCraft
API printer

Examples

Grid paper.png  Example
Writes text on the paper and then prints the cursor position.
Code
local printer = peripheral.wrap("left")

printer.newPage()
printer.write("Hello, World!")

local x, y = printer.getCursorPos()
print("The cursor on the paper is on X: " .. x .. " and Y: " .. y)

printer.endPage()
Output The cursor on the paper is on X: 14 and Y: 1