Wesley_Alves

ComputerCraft CenterTexts on Monitor

Jul 3rd, 2014
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.73 KB | None | 0 0
  1. m = peripheral.wrap("bottom")
  2. m.clear()
  3. m.setCursorPos(1,1)
  4.  
  5. local function centerText(text)
  6.   x,y = m.getSize()
  7.   x1,y1 = m.getCursorPos()
  8.   m.setCursorPos((math.floor(x/2) - (math.floor(#text/2))), y1)
  9.   m.write(text)  
  10. end
  11.  
  12. --Call function "centerText("")" to set text
  13. --Use m.setCursorPos(1,y) to choose placement on screen
  14.  
  15.  
  16. --[[
  17. EXAMPLE
  18. y2 = 7
  19. m.setCursorPos(1, y2)
  20. m.setTextColor(colors.yellow)
  21. centerText("Welcome to TheSommer's Base!")
  22. m.setCursorPos(1, y2 + 1)
  23. centerText("If you need anything, you're welcome to borrow.")
  24. m.setCursorPos(1, y2 + 3)
  25. m.setTextColor(colors.lightBlue)
  26. centerText("youtube.com/TheSommersMC")
  27. m.setCursorPos(1, y2 + 5)
  28. m.setTextColor(colors.lime)
  29. centerText("<3 Sommer")
  30. --]]
Advertisement
Add Comment
Please, Sign In to add comment