Advertisement
Overcontrol1

Tablet

Jan 7th, 2023 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. local SERVER_ID = 1;
  2.  
  3. rednet.open("back");
  4.  
  5. function ReceiveInput(message)
  6. term.setTextColor(colors.white)
  7. print("What action do you want to do?")
  8. local Input = string.lower(read());
  9. if Input == "add" then
  10. print("What do you want to add?")
  11. local toAdd = read();
  12. rednet.send(SERVER_ID, {true, toAdd});
  13. elseif Input == "remove" then
  14. print("What line do you want to remove?")
  15. local index = tonumber(read());
  16. if type(index) == "number" then
  17. rednet.send(SERVER_ID, {false, index});
  18. else
  19. term.setTextColor(colors.red)
  20. print("Not valid index")
  21. end
  22. elseif Input == "refresh" then
  23. rednet.send(SERVER_ID, "list")
  24. else
  25. PrintList(message)
  26. ReceiveInput(message)
  27. end
  28. end
  29.  
  30. function MainThread()
  31. local id, message = rednet.receive();
  32.  
  33. if id ~= SERVER_ID or type(message) ~= "table" then return end
  34.  
  35. PrintList(message)
  36. parallel.waitForAll(ReceiveInput(message), MainThread())
  37. end
  38.  
  39. function PrintList(List)
  40. term.clear()
  41. for i, v in pairs(List) do
  42. print(i..". "..v)
  43. end
  44. end
  45.  
  46. function RequestList()
  47. rednet.send(SERVER_ID, "list")
  48. MainThread()
  49. end
  50.  
  51. RequestList()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement