Advertisement
Westar777

Explorer 4

Jan 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. -- Network Explorer
  2.  
  3. print("Network Explorer");
  4.  
  5. function getMonitor()
  6. return peripheral.find('monitor');
  7. end
  8. function getModem()
  9. return peripheral.find('modem');
  10. end
  11. function split(s, delimiter)
  12. result = {};
  13. for match in (s..delimiter):gmatch("(.-)"..delimiter) do
  14. table.insert(result, match);
  15. end
  16. return result;
  17. end
  18.  
  19. print("Searching for modem and monitor");
  20. modem = getModem();
  21. if modem == nil then
  22. print("No modem found");
  23. exit();
  24. end
  25. print("Modem found");
  26.  
  27. monitor = getMonitor();
  28. if monitor == nil then
  29. print("No monitor found");
  30. end
  31. messages = {};
  32. messageIndex = -1;
  33.  
  34. function display()
  35. local displayWidth, displayHeight = monitor.getSize();
  36. local firstIndex = messageIndex - displayHeight;
  37. if firstIndex < 0 then
  38. firstIndex = 0;
  39. end
  40. monitor.clear();
  41. monitor.setCursorPos(0, 0);
  42. monitor.write("Network Explorer by Westar");
  43. for i=firstIndex, messageIndex, 1 do
  44. monitor.write(messages[i].senderId..","..messages[i].protocol..","..messages[i].message);
  45. end
  46. end
  47. display();
  48.  
  49. while true do
  50. local senderId, message, protocol = rednet.receive();
  51. messageIndex = messageIndex + 1;
  52. message[messageIndex] = {
  53. senderId = senderId,
  54. message = message,
  55. protocol = protocol
  56. };
  57. display();
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement