Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1.  
  2. local signText = "Default sign text. To change the text, type 'edit sign' in your computer terminal"
  3. local textSize = 1
  4.  
  5. local signMonitor = nil
  6.  
  7.  
  8. if peripheral.getType("back") == "monitor" then
  9. signMonitor = peripheral.wrap("back")
  10. print("found monitor on the back")
  11. elseif peripheral.getType("left") == "monitor" then
  12. signMonitor = peripheral.wrap("left")
  13. print("found monitor on the left")
  14. elseif peripheral.getType("right") == "monitor" then
  15. signMonitor = peripheral.wrap("right")
  16. print("found monitor on the right")
  17. elseif peripheral.getType("top") == "monitor" then
  18. signMonitor = peripheral.wrap("top")
  19. print("found monitor on the top")
  20. elseif peripheral.getType("bottom") == "monitor" then
  21. signMonitor = peripheral.wrap("bottom")
  22. print("found monitor on the bottom")
  23. else
  24. print("No Monitor found")
  25. end
  26.  
  27. if signMonitor then
  28. signMonitor.clear()
  29. signMonitor.setCursorPos(1,1)
  30. signMonitor.setTextScale(textSize)
  31. local w,h = signMonitor.getSize()
  32. local len = string.len(signText)
  33. local totalLines = math.ceil(len/w)
  34. local lines = {}
  35. local words = {}
  36. print("should be "..totalLines.." lines")
  37. for word in signText:gmatch("%S+") do table.insert(words,word) end
  38. while #words>0 do
  39. local lineFinished=false
  40. local newLine = ""
  41. while lineFinished == false do
  42. if #words>0 and #newLine + #words[1] +1 < w then
  43. local word = table.remove(words,1)
  44. newLine = newLine.." "..word
  45. else
  46. table.insert(lines,newLine)
  47. print("added a new line")
  48. lineFinished=true
  49. end
  50. end
  51. end
  52.  
  53.  
  54. print(w.."/"..h)
  55.  
  56. local y = 1
  57. for i,v in ipairs(lines) do
  58. signMonitor.setCursorPos(1,y)
  59. signMonitor.write(v)
  60. y = y +1
  61. end
  62.  
  63. else
  64. print("place a monitor next to the computer and try again")
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement