Advertisement
Guest User

main

a guest
Jun 16th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. -- Wrap the modem and monitor
  2. local mon = peripheral.wrap("top")
  3. local wmod = peripheral.wrap("back")
  4.  
  5. -- Close all channels by default in case
  6. -- users have other transmissions in air
  7. wmod.closeAll()
  8.  
  9. -- Open different channels for different liquids
  10. -- Only 2+3 are open by default, open the
  11. -- ones you're using to prevent errors.
  12. wmod.open(2)   -- water?
  13. wmod.open(3)   -- lava?
  14. --wmod.open(4)   -- x
  15. --wmod.open(5)   -- x
  16. --wmod.open(6)   -- x
  17. --wmod.open(7)   -- x
  18. --wmod.open(8)   -- x
  19. --wmod.open(9)   -- x
  20. --wmod.open(10)  -- x
  21. --wmod.open(11)  -- x
  22. --wmod.open(12)  -- x
  23.  
  24. mon.clear()
  25. mon.setTextColor(colors.white)
  26. mon.setCursorPos(1,1)
  27. mon.write("Tank:")
  28.  
  29. -- Main loop, never stop
  30. while true do
  31.  
  32.   -- Check for incoming data on any open channel
  33.   local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  34.  
  35.   -- Add one case for every liquid
  36.   -- Change channel and text for each
  37.  
  38.   -- First check color
  39.   if string.match(message, ".red.") then
  40.     mon.setTextColor(colors.red)
  41.     message = string.gsub(message, ".red.", "")
  42.   elseif string.match(message, ".green.") then
  43.     mon.setTextColor(colors.green)
  44.     message = string.gsub(message, ".green.", "")
  45.   end
  46.  
  47. -- I have prepared for 11 channels.
  48. -- They should match channels up at top!
  49.  
  50.   if senderChannel == 2 then
  51.     mon.setCursorPos(1,2)
  52.   elseif senderChannel == 3 then
  53.     mon.setCursorPos(1,2)
  54.   elseif senderChannel == 4 then
  55.     mon.setCursorPos(1,4)
  56.   elseif senderChannel == 5 then
  57.     mon.setCursorPos(1,5)
  58.   elseif senderChannel == 6 then
  59.     mon.setCursorPos(1,6)
  60.   elseif senderChannel == 7 then
  61.     mon.setCursorPos(1,7)
  62.   elseif senderChannel == 8 then
  63.     mon.setCursorPos(1,8)
  64.   elseif senderChannel == 9 then
  65.     mon.setCursorPos(1,9)
  66.   elseif senderChannel == 10 then
  67.     mon.setCursorPos(1,10)      
  68.   elseif senderChannel == 11 then
  69.     mon.setCursorPos(1,11)
  70.   elseif senderChannel == 12 then
  71.     mon.setCursorPos(1,12)
  72.   end
  73.    
  74.   mon.write(message .."        ")
  75.   print("Received " ..message)
  76. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement