Difference between revisions of "Printer.setCursorPos"

From ComputerCraft Wiki
Jump to: navigation, search
(Changing int to number)
m (Expanded)
 
Line 1: Line 1:
 
{{lowercase}}
 
{{lowercase}}
 
{{Function
 
{{Function
|name=printer.setCursorPos
+
|name=''printer''.setCursorPos
 
|args={{type|number}} x, {{type|number}} y
 
|args={{type|number}} x, {{type|number}} y
|returns=none
+
|returns={{type|nil}}
 
|api=printer
 
|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()