Corbinhol

newFurnaceSystem

Sep 25th, 2022 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. rednet.open("top");
  2. rednet.host("API", "FurnaceSystem");
  3.  
  4. local status = "loading...";
  5.  
  6. function getData()
  7. local connected = 0;
  8. for i = 1,8,1 do
  9. local furnace = rednet.lookup("furnaceSystem", "Furnace" .. i);
  10. if furnace ~= nil then
  11. rednet.send(furnace, "getStatus", "furnaceSystem");
  12. local from, message = rednet.receive("furnaceSystem", 1);
  13. end
  14.  
  15. if message == nil then message = false end
  16. if from == furnace and message == true then
  17. connected = connected + 1;
  18. end
  19. end
  20. if connected == 0 then return "Offline";
  21. elseif connected > 0 and connected < 8 then return "Partially Online"
  22. elseif connected == 8 then return "Online";
  23. end
  24. end
  25.  
  26. function main()
  27. while true do
  28. status = getData();
  29. sleep(0);
  30. end
  31. end
  32.  
  33. function api()
  34. while true do
  35. local from, message = rednet.receive("API");
  36. if message == "getFurnaceData" then
  37. print(status);
  38. rednet.send(from, status, "API");
  39. end
  40. sleep(0);
  41. end
  42. end
  43.  
  44. parallel.waitForAny(main, api);
Add Comment
Please, Sign In to add comment