Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- WirelessMonitor.lua
- -- Version 1.11
- -- Author: Modified by AshGrey
- -- Date: 2024-10-16
- -------------------------------------------------------------------------------
- -- INITIALIZATION
- -------------------------------------------------------------------------------
- local monitor = peripheral.wrap("right") -- Adjust if necessary
- if not monitor then error("Monitor not found.") end
- monitor.setTextScale(0.5)
- monitor.clear()
- print("Monitor initialized.")
- local modem = peripheral.wrap("left") -- Adjust if necessary
- if not modem then error("Ender Modem not found.") end
- print("Ender Modem initialized.")
- local maxLines = monitor.getSize() -- Get the maximum lines the monitor can display
- local maxWidth = monitor.getSize() -- Get the maximum width of the monitor
- local currentLine = 1 -- Initialize current line position
- local lineLimit = 50 -- Set the number of lines before clearing
- -------------------------------------------------------------------------------
- -- FUNCTIONS
- -------------------------------------------------------------------------------
- function displayMessage(message)
- if currentLine > lineLimit then
- monitor.clear() -- Clear the monitor if line limit is exceeded
- currentLine = 1 -- Reset current line position
- end
- -- Split the message into multiple lines based on the maximum width
- for line in string.gmatch(message, "([^\n]*)\n?") do
- if line ~= "" then
- while #line > maxWidth do
- -- Split long lines into manageable pieces
- local part = string.sub(line, 1, maxWidth)
- line = string.sub(line, maxWidth + 1)
- printToMonitor(part) -- Print part to monitor
- end
- printToMonitor(line) -- Print remaining line
- end
- end
- end
- function printToMonitor(msg)
- if currentLine > maxLines then
- monitor.scroll(1) -- Scroll up to make space
- currentLine = maxLines -- Reset to the maximum
- end
- monitor.setCursorPos(1, currentLine)
- monitor.write(msg) -- Write the message
- currentLine = currentLine + 1 -- Move to the next line
- end
- -------------------------------------------------------------------------------
- -- MAIN LOOP
- -------------------------------------------------------------------------------
- print("Starting Wireless Monitor...")
- modem.open(1)
- while true do
- local event, side, channel, replyChannel, message = os.pullEvent("modem_message")
- if channel == 1 then
- print("Received message: " .. message) -- Debugging output
- displayMessage(message) -- Add message to the monitor
- else
- print("Ignored message from channel: " .. channel) -- More debugging
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement