Difference between revisions of "Printer.setCursorPos"

From ComputerCraft Wiki
Jump to: navigation, search
m (Reverted edits by 199.19.105.156 (talk) to last revision by Lyqyd)
m (Expanded)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
 
{{Function
 
{{Function
|name=printer.setCursorPos
+
|name=''printer''.setCursorPos
|args=[[int (type)|int]] x, [[int (type)|int]] y
+
|args={{type|number}} x, {{type|number}} y
|returns=none
+
|returns={{type|nil}}
|api=peripheral
+
|api=printer
 
|addon=ComputerCraft
 
|addon=ComputerCraft
|desc=Sets the position of the printer cursor, similar to [[term.setCursorPos]], but on a printer.
+
|desc=Sets the cursor position on the page, works the same way as [[term.setCursorPos]]().
 
|examples=
 
|examples=
 
{{Example
 
{{Example
|desc=Sets the cursor at the top of the page.
+
|desc=Sets the cursor position to the center of the paper and prints "X".
|code=printer.setCursorPos(1,1)
+
|code= local printer = [[peripheral.wrap]]("left")
|output=none
+
 +
[[printer.newPage]]()
 +
 +
local width, height = [[printer.getPageSize]]()
 +
 +
printer.setCursorPos([[Math (API)|math]].floor(width/2), [[Math (API)|math]].floor(height/2))
 +
[[printer.write]]("X")
 +
 +
[[printer.endPage]]()
 
}}
 
}}
 
}}
 
}}
  
 
[[Category:Lua_Core_Functions]]
 
[[Category:Lua_Core_Functions]]

Latest revision as of 18:58, 9 April 2014


Grid Redstone.png  Function printer.setCursorPos
Sets the cursor position on the page, works the same way as term.setCursorPos().
Syntax printer.setCursorPos(number x, number y)
Returns nil
Part of ComputerCraft
API printer

Examples

Grid paper.png  Example
Sets the cursor position to the center of the paper and prints "X".
Code
local printer = peripheral.wrap("left")

printer.newPage()

local width, height = printer.getPageSize()

printer.setCursorPos(math.floor(width/2), math.floor(height/2))
printer.write("X")

printer.endPage()