Advertisement
Guest User

startup

a guest
Feb 22nd, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.41 KB | None | 0 0
  1. function turtleWrite(turtX, turtY, turtZ, turtDir, address)
  2.   local a = fs.open("turt"..address, "w")
  3.   a.writeLine(turtX)
  4.   a.writeLine(turtY)
  5.   a.writeLine(turtZ)
  6.   a.writeLine(turtDir)
  7.   a.close()
  8. end
  9. function turtleRead(address)
  10.   local a = fs.open("turt"..address, "r")
  11.   local x = a.readLine()
  12.   local y = a.readLine()
  13.   local z = a.readLine()
  14.   local dir = a.readLine()
  15.   print("Sending an update to turtle " ..address.. "!")
  16.   rednet.send(address, x)
  17.   rednet.send(address, y)
  18.   rednet.send(address, z)
  19.   rednet.send(address, dir)
  20. end
  21. print("Ready to receive signals!")
  22. rednet.open("right")
  23. while true do
  24.   local id, command = rednet.receive()
  25.   if command == "updatePos" then
  26.     local flag = true
  27.     while flag do
  28.       local address, x = rednet.receive()
  29.       if address == id then
  30.         flag = false
  31.       end
  32.     end
  33.     local flag = true
  34.     while flag do
  35.       local address, y = rednet.receive()
  36.       if address == id then
  37.         flag = false
  38.       end
  39.     end
  40.     local flag = true
  41.     while flag do
  42.       local address, z = rednet.receive()
  43.       if address == id then
  44.         flag = false
  45.       end
  46.     end
  47.     local flag = true
  48.     while flag do
  49.       local address, dir = rednet.receive()
  50.       if address == id then
  51.         flag = false
  52.       end
  53.     end
  54.     turtleWrite(x, y, z, dir, id)
  55.   elseif command == "needUpdate" then
  56.     turtleRead(id)
  57.   end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement