Advertisement
JackGrey

WirelessMonitor 2.0 WIP Do not use

Oct 16th, 2024 (edited)
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. -- WirelessMonitor.lua
  2. -- Version 1.11
  3. -- Author: Modified by AshGrey
  4. -- Date: 2024-10-16
  5.  
  6. -------------------------------------------------------------------------------
  7. -- INITIALIZATION
  8. -------------------------------------------------------------------------------
  9.  
  10. local monitor = peripheral.wrap("right") -- Adjust if necessary
  11. if not monitor then error("Monitor not found.") end
  12. monitor.setTextScale(0.5)
  13. monitor.clear()
  14. print("Monitor initialized.")
  15.  
  16. local modem = peripheral.wrap("left") -- Adjust if necessary
  17. if not modem then error("Ender Modem not found.") end
  18. print("Ender Modem initialized.")
  19.  
  20. local maxLines = monitor.getSize() -- Get the maximum lines the monitor can display
  21. local maxWidth = monitor.getSize() -- Get the maximum width of the monitor
  22. local currentLine = 1 -- Initialize current line position
  23. local lineLimit = 50 -- Set the number of lines before clearing
  24.  
  25. -------------------------------------------------------------------------------
  26. -- FUNCTIONS
  27. -------------------------------------------------------------------------------
  28.  
  29. function displayMessage(message)
  30. if currentLine > lineLimit then
  31. monitor.clear() -- Clear the monitor if line limit is exceeded
  32. currentLine = 1 -- Reset current line position
  33. end
  34.  
  35. -- Split the message into multiple lines based on the maximum width
  36. for line in string.gmatch(message, "([^\n]*)\n?") do
  37. if line ~= "" then
  38. while #line > maxWidth do
  39. -- Split long lines into manageable pieces
  40. local part = string.sub(line, 1, maxWidth)
  41. line = string.sub(line, maxWidth + 1)
  42. printToMonitor(part) -- Print part to monitor
  43. end
  44. printToMonitor(line) -- Print remaining line
  45. end
  46. end
  47. end
  48.  
  49. function printToMonitor(msg)
  50. if currentLine > maxLines then
  51. monitor.scroll(1) -- Scroll up to make space
  52. currentLine = maxLines -- Reset to the maximum
  53. end
  54.  
  55. monitor.setCursorPos(1, currentLine)
  56. monitor.write(msg) -- Write the message
  57. currentLine = currentLine + 1 -- Move to the next line
  58. end
  59.  
  60. -------------------------------------------------------------------------------
  61. -- MAIN LOOP
  62. -------------------------------------------------------------------------------
  63.  
  64. print("Starting Wireless Monitor...")
  65. modem.open(1)
  66.  
  67. while true do
  68. local event, side, channel, replyChannel, message = os.pullEvent("modem_message")
  69. if channel == 1 then
  70. print("Received message: " .. message) -- Debugging output
  71. displayMessage(message) -- Add message to the monitor
  72. else
  73. print("Ignored message from channel: " .. channel) -- More debugging
  74. end
  75. end
  76.  
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement