Glitchies

turtle.spiral

Jan 31st, 2014
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.45 KB | None | 0 0
  1. peripheral.wrap("right")
  2. local tArgs = {...}
  3. local file = fs.open("save", "r")
  4. local y = file.readAll()
  5. file.close()
  6.  
  7. if tArgs[1] == nil then tArgs[1] = 1 end
  8. function legs()
  9.    for i = 1, y do
  10.           turtle.forward()
  11.    end
  12.    turtle.turnLeft()
  13.    y = y + 32
  14. end
  15.  
  16. function locate()
  17.    local xIni, yIni, zIni
  18.    local xCur, yCur, zCur
  19.    local fCur
  20.    local posOut
  21.  
  22.    xIni, yIni, zIni = gps.locate(5)
  23.  
  24.    if not xIni or not yIni or not zIni then
  25.      print("No or insufficient GPS hosts found")
  26.      do return end
  27.    end
  28.  
  29.    while not turtle.forward() do
  30.      while not turtle.up() do
  31.        turtle.digUp()
  32.      end
  33.    end
  34.  
  35.    xCur, yCur, zCur = gps.locate(5)
  36.    if zCur > zIni then
  37.      fCur = 0
  38.    elseif xCur < xIni then
  39.      fCur = 1
  40.    elseif zCur < zIni then
  41.      fCur = 2
  42.    elseif xCur > xIni then
  43.      fCur = 3
  44.    else
  45.      exit()
  46.    end
  47.  
  48.    while not turtle.back() do
  49.      while not turtle.up() do
  50.        turtle.digUp()
  51.      end
  52.    end
  53.  
  54.    xCur, yCur, zCur = gps.locate(5)
  55.  
  56.    if not fs.isDir("data") then
  57.    fs.delete("data")
  58.    fs.makeDir("data")
  59.    end
  60.  
  61.    posOut = io.open("data/pos.txt", "w")
  62.    posOut:write(textutils.serialize({xCur, yCur, zCur, fCur}))
  63.    posOut:close()
  64. end
  65. function whole()
  66.    for i = 1, 4 do
  67.           legs()
  68.    end
  69. --   file = io.open("save" , "w")
  70. --   file:write(textutils.serialize({y}))
  71. --   file.close()
  72. end
  73. for i = 1, tArgs[1] do
  74.    whole()
  75.    locate()
  76. end
Advertisement
Add Comment
Please, Sign In to add comment