Guest User

skyside

a guest
Nov 1st, 2012
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. local stop = 0
  2. local fuellevel = 0
  3. local ox, oy, oz = nil, nil, nil
  4. cx, cy, cz = nil, nil, nil
  5. local turned = 0
  6. -- local  x,  y,  z = nil, nil, nil
  7. direct = 0
  8.  
  9. rednet.open("right")
  10. ox, oy, oz = gps.locate(3)
  11.  
  12. function  doit()
  13.    fuellevel = turtle.getFuelLevel()
  14.    print("fuellevel = "..fuellevel)
  15.    if fuellevel == 0 then
  16.       print("Please put fuel in slot1.")
  17.       while fuellevel == 0 do
  18.          turtle.refuel()
  19.          fuellevel = turtle.getFuelLevel()
  20.          os.sleep(1)
  21.       end
  22.       print("Thank you :D")
  23.     end
  24. end
  25.  
  26. function finddirect1()
  27.    if not turtle.forward() then
  28.        if turned ~= 3 then
  29.           turtle.turnRight()
  30.           turned = turned + 1
  31.           finddirect1()
  32.        else
  33.            print("I need space in front of me!")
  34.        end
  35.    else  
  36.    finddirect2()
  37.    end
  38. end
  39.  
  40.    
  41. function finddirect2()
  42. cx, cy, cz = gps.locate(3)
  43.    if cx and cy and cz then
  44.       if cx < ox then
  45.          direct = 3
  46.       end
  47.       if cx > ox then
  48.          direct = 1
  49.       end
  50.       if cz < oz then
  51.          direct = 4
  52.       end
  53.       if cz > oz then
  54.          direct = 2
  55.       end
  56.    else
  57.       print("fail")
  58.    end
  59. end
  60.  
  61.      
  62. if ox and oy and oz then
  63.    print(ox..", "..oy..", "..oz)
  64.    doit()
  65.    finddirect1()
  66.    if stop == 0 then
  67.       print(""..direct)
  68.    end
  69.    cx, cy, cz = gps.locate(3)
  70. else
  71.    print("Couldn't get position")
  72. end
Advertisement
Add Comment
Please, Sign In to add comment