Advertisement
MrSliff

reactor

Jan 20th, 2025 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. local reactor = {}
  2.  
  3. local function reactor.findReactors(reactor_protocol)
  4. local lookup = {rednet.lookup(reactor_protocol)}
  5. local reactors = {}
  6. for i=1,#lookup do
  7. reactors[i] = {id = lookup[i]}
  8. end
  9.  
  10. print("Found Reactors: ")
  11. for i,#reactors do
  12. print("Reactor %d:", reactor[i])
  13. for key, print(key .. ": " .. value)
  14. end
  15. return reactors
  16. end
  17.  
  18. local function reactor.getReactorInfo(reactorID, reactor_protocol)
  19. rednet.send(reactorID, "getInfo", reactor_protocol)
  20. local id, message = rednet.receive(reactor_protocol, 1)
  21. if id == reactors[i]["id"] then
  22. for key, value in pairs(message) do
  23. reactors[i][key] = value
  24. end
  25. end
  26. return reactors
  27. end
  28.  
  29. local function reactor.setReactorState(reactorID, state, reactor_protocol)
  30. rednet.send(reactorID, "setState", reactor_protocol)
  31. local id, message = rednet.receive(reactor_protocol, 1)
  32. if id == reactorID && message == state then
  33. return true
  34. else
  35. return false
  36. end
  37. end
  38.  
  39. return reactor -- {findReactors = findReactors, getReactorInfo = getReactorInfo, setReactorState = setReactorState}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement