Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Monitor Display Script for All the Mods 10 (ComputerCraft)
- -- Author: Your Name/AI Assistant
- -- Date: July 7, 2025
- -- This script allows you to input text and display it on all connected monitors.
- -- === Configuration ===
- -- You can set a default text color here if you wish.
- -- Valid colors: white, orange, magenta, lightBlue, yellow, lime, pink, gray,
- -- lightGray, cyan, purple, blue, brown, green, red, black
- local textColor = colors.white
- local backgroundColor = colors.black
- -- === Main Script ===
- -- Function to clear all connected monitors
- local function clearMonitors()
- for _, peripheralName in ipairs(peripheral.getNames()) do
- if peripheral.getType(peripheralName) == "monitor" then
- local monitor = peripheral.wrap(peripheralName)
- if monitor then
- monitor.clear()
- monitor.setBackgroundColor(backgroundColor)
- monitor.setTextColor(textColor)
- end
- end
- end
- end
- -- Function to display text on all connected monitors
- local function displayTextOnMonitors(textToDisplay)
- clearMonitors() -- Clear before displaying new text
- for _, peripheralName in ipairs(peripheral.getNames()) do
- if peripheral.getType(peripheralName) == "monitor" then
- local monitor = peripheral.wrap(peripheralName)
- if monitor then
- local termWidth, termHeight = monitor.getSize()
- local x = math.floor((termWidth - #textToDisplay) / 2)
- local y = math.floor(termHeight / 2)
- monitor.setCursorPos(x > 1 and x or 1, y > 1 and y or 1)
- monitor.write(textToDisplay)
- end
- end
- end
- end
- -- Main loop for user interaction
- print("Monitor Display Script")
- print("-----------------------")
- print("Enter text to display on monitors. Type 'exit' to quit.")
- while true do
- io.write("Enter text: ")
- local inputText = io.read()
- if inputText then
- if string.lower(inputText) == "exit" then
- clearMonitors() -- Clear monitors on exit
- print("Exiting script. Goodbye!")
- break
- else
- displayTextOnMonitors(inputText)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment