window.getPosition

From ComputerCraft Wiki
Jump to: navigation, search


Grid Redstone.png  Function window.getPosition
A function available to window-based terminal objects created via the window API, which returns the x/y co-ordinates of the window's top-left point (within its parent terminal object).

See also: term.getSize(), window.reposition()
Syntax window.getPosition()
Returns number xPosition, number yPosition
Part of ComputerCraft
API term

Examples

Grid paper.png  Example
Defines a child window in a parent window, and notes its location within that parent. Moves the parent and notes the location again, before moving the child window and making a final note.
Code
term.clear()
term.setCursorPos(1,1)
local lastX, lastY

local parentWindow = window.create(term.current(), 5, 5, 10, 10)
local childWindow = window.create(parentWindow, 2, 2, 1, 1)
childWindow.write("!")

term.setCursorPos(1,1)
local xPos, yPos = childWindow.getPosition()
print("Child window is initially at "..xPos.."x"..yPos..".")
lastX, lastY = term.getCursorPos()

parentWindow.reposition(10,10)

term.setCursorPos(lastX,lastY)
xPos, yPos = childWindow.getPosition()
print("After moving the parent window, child window still registers as being at "..xPos.."x"..yPos..".")
lastX, lastY = term.getCursorPos()

childWindow.reposition(7,7)

term.setCursorPos(lastX,lastY)
xPos, yPos = childWindow.getPosition()
print("After moving the child window, it now registers as being at "..xPos.."x"..yPos..".")
Output Notes that:
Child window is initially at 2x2.
After moving the parent window, child window still registers as being at 2x2.
After moving the child window, it now registers as being at 7x7.
... and also displays the exclamation mark rendered within the child window (drawn at three different positions).
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox