Advertisement
JackGrey

Receive to monitor

Oct 16th, 2024 (edited)
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.04 KB | None | 0 0
  1. -- WirelessMonitor.lua
  2. -- Version 1.1
  3. -- Author: Modified by AshGrey
  4. -- Date: 2024-10-16
  5.  
  6. -- This script runs on the wireless computer with a monitor to display missing items from the AE2 Warehouse.
  7.  
  8. -------------------------------------------------------------------------------
  9. -- INITIALIZATION
  10. -------------------------------------------------------------------------------
  11.  
  12. -- Initialize the wireless monitor
  13. local monitor = peripheral.wrap("right") -- Adjust if necessary
  14. if not monitor then error("Monitor not found.") end
  15. monitor.setTextScale(0.5)
  16. monitor.clear()
  17. print("Monitor initialized.")
  18.  
  19. -- Initialize the Ender Modem
  20. local modem = peripheral.wrap("left") -- Adjust if necessary
  21. if not modem then error("Ender Modem not found.") end
  22. print("Ender Modem initialized.")
  23.  
  24. -------------------------------------------------------------------------------
  25. -- FUNCTIONS
  26. -------------------------------------------------------------------------------
  27.  
  28. -- Display the missing items received from the main computer
  29. function displayMissingItems(missingItems)
  30. monitor.clear()
  31. monitor.setCursorPos(1, 1)
  32. monitor.write("Missing Items:")
  33.  
  34. local line = 2
  35. for item in string.gmatch(missingItems, "([^;]+)") do
  36. local name, count = item:match("([^:]+):([^:]+)")
  37. if name and count then
  38. monitor.setCursorPos(1, line)
  39. monitor.write(name .. ": " .. count)
  40. line = line + 1
  41. end
  42. end
  43. end
  44.  
  45. -------------------------------------------------------------------------------
  46. -- MAIN LOOP
  47. -------------------------------------------------------------------------------
  48.  
  49. print("Starting Wireless Monitor...")
  50. modem.open(1) -- Open a channel (choose any number)
  51.  
  52. while true do
  53. -- Listen for messages from the main computer
  54. local event, side, channel, replyChannel, message = os.pullEvent("modem_message")
  55. if channel == 1 then -- Ensure it matches the opened channel
  56. displayMissingItems(message) -- Display the missing items on the monitor
  57. end
  58. end
  59.  
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement