melzneni

TURTI_InitTurti

Oct 3rd, 2021 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. local modemSide
  2. for _, name in ipairs(peripheral.getNames()) do
  3. if peripheral.getType(name) == "modem" then
  4. modemSide = name
  5. end
  6. end
  7. if modemSide == nil then
  8. error("no modem connected")
  9. end
  10.  
  11. rednet.open(modemSide)
  12. print("sending initialization beacon")
  13. rednet.broadcast({ at = "mainFrame", command = { "turti", "init" } })
  14.  
  15. while true do
  16. local id, msg = rednet.receive(5)
  17. if not id then
  18. print("sending initialization beacon")
  19. rednet.broadcast({ at = "mainFrame", command = { "turti", "init" } })
  20. else
  21. if msg.at == "turtle" then
  22. if msg.command[1] == "mainFrame" then
  23. --[[ if msg.command[2] == "update" then
  24. print(index)
  25. else
  26. print("unknown command: " .. msg.command[2])
  27. end]]
  28. elseif msg.command[1] == "initData" then
  29. local data = msg.data
  30. write("writing init files... ")
  31. for name, content in pairs(data.setupFiles) do
  32. local file = fs.open(name, "w")
  33. file.write(content)
  34. file.close()
  35. end
  36. print("done")
  37. if data.executeFile then
  38. print("executing '" .. data.executeFile .. "'...")
  39. print()
  40. shell.run(data.executeFile)
  41. return
  42. end
  43. else
  44. print("unknown command: " .. msg.command[1])
  45. end
  46. end
  47. end
  48. end
  49.  
Add Comment
Please, Sign In to add comment