Advertisement
JackGrey

WirelessPocketComputerMonitor

Oct 16th, 2024 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. -- WirelessReceiver.lua
  2. -- Version 1.0
  3. -- Author: AshGrey
  4. -- Date: 2024-10-16
  5.  
  6. -- This script listens for transmitted missing item data from the AE2Warehouse script
  7. -- and displays the information on the wireless pocket computer.
  8.  
  9. -------------------------------------------------------------------------------
  10. -- INITIALIZATION
  11. -------------------------------------------------------------------------------
  12.  
  13. -- Initialize Ender Modem
  14. local modem = peripheral.wrap("back") -- Wrap the Ender Modem on the left side
  15. if not modem then error("Ender Modem not found.") end
  16. print("Ender Modem initialized.")
  17.  
  18. -- Set the modem to listen on the specified channel
  19. local channel = 1
  20. modem.open(channel)
  21. print("Listening for missing items on channel:", channel)
  22.  
  23. -------------------------------------------------------------------------------
  24. -- MAIN LOOP
  25. -------------------------------------------------------------------------------
  26.  
  27. while true do
  28. -- Wait for a message on the specified channel
  29. local senderID, receivedChannel, message = os.pullEvent("modem_message")
  30.  
  31. -- Ensure the message is on the right channel
  32. if receivedChannel == channel then
  33. print("Received missing items data:", message)
  34.  
  35. -- Display the missing items
  36. print("Missing Items:")
  37. for itemData in message:gmatch("[^;]+") do
  38. local itemName, count = itemData:match("([^:]+):([^:]+)")
  39. print(itemName .. ": " .. count)
  40. end
  41. end
  42.  
  43. -- Short sleep to prevent CPU overuse
  44. sleep(0.5)
  45. end
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement