Guest User

Untitled

a guest
Jul 7th, 2025
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. -- Monitor Display Script for All the Mods 10 (ComputerCraft)
  2. -- Author: Your Name/AI Assistant
  3. -- Date: July 7, 2025
  4.  
  5. -- This script allows you to input text and display it on all connected monitors.
  6.  
  7. -- === Configuration ===
  8. -- You can set a default text color here if you wish.
  9. -- Valid colors: white, orange, magenta, lightBlue, yellow, lime, pink, gray,
  10. -- lightGray, cyan, purple, blue, brown, green, red, black
  11. local textColor = colors.white
  12. local backgroundColor = colors.black
  13.  
  14. -- === Main Script ===
  15.  
  16. -- Function to clear all connected monitors
  17. local function clearMonitors()
  18. for _, peripheralName in ipairs(peripheral.getNames()) do
  19. if peripheral.getType(peripheralName) == "monitor" then
  20. local monitor = peripheral.wrap(peripheralName)
  21. if monitor then
  22. monitor.clear()
  23. monitor.setBackgroundColor(backgroundColor)
  24. monitor.setTextColor(textColor)
  25. end
  26. end
  27. end
  28. end
  29.  
  30. -- Function to display text on all connected monitors
  31. local function displayTextOnMonitors(textToDisplay)
  32. clearMonitors() -- Clear before displaying new text
  33.  
  34. for _, peripheralName in ipairs(peripheral.getNames()) do
  35. if peripheral.getType(peripheralName) == "monitor" then
  36. local monitor = peripheral.wrap(peripheralName)
  37. if monitor then
  38. local termWidth, termHeight = monitor.getSize()
  39. local x = math.floor((termWidth - #textToDisplay) / 2)
  40. local y = math.floor(termHeight / 2)
  41.  
  42. monitor.setCursorPos(x > 1 and x or 1, y > 1 and y or 1)
  43. monitor.write(textToDisplay)
  44. end
  45. end
  46. end
  47. end
  48.  
  49. -- Main loop for user interaction
  50. print("Monitor Display Script")
  51. print("-----------------------")
  52. print("Enter text to display on monitors. Type 'exit' to quit.")
  53.  
  54. while true do
  55. io.write("Enter text: ")
  56. local inputText = io.read()
  57.  
  58. if inputText then
  59. if string.lower(inputText) == "exit" then
  60. clearMonitors() -- Clear monitors on exit
  61. print("Exiting script. Goodbye!")
  62. break
  63. else
  64. displayTextOnMonitors(inputText)
  65. end
  66. end
  67. end
Advertisement
Add Comment
Please, Sign In to add comment