Advertisement
sosochka

stripMineHost.lua

Dec 21st, 2022
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. clientsSuccseeded = 0
  2. clientsAmount = 0
  3. modem = peripheral.find("modem")
  4. transmitChannel = 229
  5. receiveChannel = 228
  6. modem.closeAll()
  7. modem.open(receiveChannel)
  8.  
  9. local function mainLoop()
  10. while true do
  11. if clientsSuccseeded == clientsAmount then
  12. modem.transmit(transmitChannel, transmitChannel, "continue")
  13. clientsSuccseeded = 0
  14. end
  15. print("clientsSuccseeded", clientsSuccseeded)
  16. sleep(1)
  17. end
  18. end
  19.  
  20. local function receiveClientMessages()
  21. while true do
  22. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  23. print(message)
  24. if message == "completedTurn" then
  25. print("Recieved completed message from client")
  26. clientsSuccseeded = clientsSuccseeded + 1
  27. end
  28. end
  29. end
  30.  
  31. term.clear()
  32. term.setCursorPos(1, 1)
  33. print("How many clients are there?")
  34. clientsAmount = tonumber(io.stdin:read())
  35.  
  36. term.clear()
  37. term.setCursorPos(1, 1)
  38. print("Press any button to start")
  39. os.pullEvent("key")
  40.  
  41. term.clear()
  42. term.setCursorPos(1, 1)
  43. print("Started")
  44. modem.transmit(transmitChannel, transmitChannel, "start")
  45.  
  46. parallel.waitForAny(mainLoop, receiveClientMessages)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement