Guest User

goto

a guest
Oct 17th, 2012
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. -- north=1, east=2, south=3, west=4
  2.  
  3. local ox, oy, oz = nil, nil, nil
  4. local endx, endy, endz = nil, nil, nil
  5. local stuck = 0
  6.  
  7.  
  8. function getpos()
  9.    rednet.open("right")
  10.    cx, cy, cz = gps.locate(1)
  11. end
  12.  
  13. getpos()
  14.  
  15.  
  16. print("Wohin solls gehen?")
  17. write("x: ")
  18. nx = read()
  19.  
  20. write("y: ")
  21. ny = read()
  22.  
  23. write("z: ")
  24. nz = read()
  25.  
  26. write("In welche Richtung gucken (1-4)?")
  27. ndirect = read()
  28.  
  29. function directto(x)
  30.    while ndirect ~= direct do
  31.       turtle.turnRight()
  32.       if direct ~= 4 then
  33.          direct = direct + 1
  34.       else
  35.          direct = 1
  36.       end
  37.    end  
  38.    
  39. function gox1()
  40.    if cx < nx then
  41.       directto(1)  
  42.       if turtle.forward() then
  43.          cx = cx - 1
  44.          gox1()
  45.       else
  46.          gox3()
  47.       end
  48.    end
  49. end
  50.          
  51. function gox3()
  52.    if cx > nx then
  53.       directto(3)
  54.       if turtle.forward() then
  55.          cx = cx +1
  56.          gox3()
  57.       else
  58.          goz2()
  59.       end
  60.    end
  61. end
  62.  
  63. function goz2()
  64.    if cz < nz then
  65.       directto(2)
  66.       if turtle.forward() then
  67.          cz = cz + 1
  68.          goz2()
  69.       else
  70.          goz4()
  71.       end
  72.    end
  73. end
  74.  
  75. function goz4()
  76.    if cz > nz then
  77.       directto(4)
  78.       if turtle.forward() then
  79.          cz = cz - 1
  80.          goz4()
  81.       else
  82.          goyu()
  83.       end
  84.    end
  85. end
  86.  
  87. function goyu()
  88.    if cy < ny then
  89.       if turtle.up() then
  90.          cy = cy + 1
  91.          goyu()
  92.       else
  93.          goyd()
  94.       end
  95.    end
  96. end
  97.  
  98. function goyd()
  99.    if cy > ny then
  100.       if turtle.down() then
  101.          cy = cy -1
  102.          goyd()
  103.       else
  104.          chegfuel()
  105.       end
  106.    end
  107. end
  108.  
  109. function chegfuel()
  110.    if turtle.getFuelLevel > 0 and stuck = 0 then
  111.       if turtle.up() then
  112.          gox1()
  113.       elseif stuck < 1
  114.          stuck = 1
  115.          os.sleep(5)
  116.          gox1()
  117.       end
  118.    else
  119.       if turtle.getFuelLevel = 0 then
  120.          print("I need more fuel!")
  121.          while turtle.getFuelLevel = 0 do
  122.             os.sleep(5)
  123.             turtle.refuel()
  124.          end
  125.          gox1()
  126.       else
  127.          print("Help my I'm stuck!")
  128.          print("Shut down the programm.")
  129.       end
  130.    end    
  131. end      
  132.    
  133.                      
  134. if not nx then
  135.    nx = cx
  136. end
  137. if not ny then
  138.    ny = cx
  139. end
  140. if not nz then
  141.    nz = cz
  142. end
  143.  
  144. shell.run("skyside")
  145. if direct ~= nil then
  146.    gox1()
  147.    getpos()
  148.    gox1()
  149. end
Advertisement
Add Comment
Please, Sign In to add comment