Suterusu

OC - funcs

Sep 12th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.05 KB | None | 0 0
  1. local function feedGenerator()
  2.     for i = robotFirstInventorySlot, robot.inventorySize(), 1 do
  3.         robot.select(i)
  4.         if gen.insert(16) then
  5.             return
  6.         end
  7.     end
  8. end
  9.  
  10. local function purge()
  11.     for i = robotFirstInventorySlot, robot.inventorySize(), 1 do
  12.         robot.select(i)
  13.         if robot.compareTo(3) or robot.compareTo(4) or robot.compareTo(5) then
  14.             robot.drop()
  15.         end
  16.     end
  17. end
  18.  
  19. local function changeDirection()
  20.     if direction == "front" then
  21.         direction = "back"
  22.     elseif direction == "back" then
  23.         direction = "front"
  24.     end
  25. end
  26.  
  27. local function turnLeft()
  28.     robot.turnLeft()
  29.     robot.swing()
  30.     robot.forward()
  31.     robot.turnLeft()
  32. end
  33.  
  34. local function turnRight()
  35.     robot.turnRight()
  36.     robot.swing()
  37.     robot.forward()
  38.     robot.turnRight()
  39. end
  40.  
  41. local function moving(distanceFront, distanceSide, distanceDown)
  42.     local k = 0
  43.     while k < distanceDown do
  44.         print(k)
  45.         local j = 0
  46.         while j < distanceSide -1 do
  47.             print(j)
  48.             local i = 0
  49.             while i < distanceFront - 1 do
  50.                 print(i)
  51.                 robot.swing() -- action here
  52.                 if robot.forward() then
  53.                     i = i + 1
  54.                 end
  55.             end
  56.             if computer.energy() < 5000 then
  57.                 feedGenerator()
  58.             end
  59.             if distanceSide % 2 == 0 then
  60.                 if direction == "front" then
  61.                     if j % 2 == 0 then
  62.                         turnRight()
  63.                     else
  64.                         turnLeft()
  65.                     end
  66.                 elseif direction == "back" then
  67.                     if j % 2 == 0 then
  68.                         turnLeft()
  69.                     else
  70.                         turnRight()
  71.                     end
  72.                 end
  73.             else
  74.                 if direction == "front" then
  75.                     if j % 2 == 0 then
  76.                         turnRight()
  77.                     else
  78.                         turnLeft()
  79.                     end
  80.                 elseif direction == "back" then
  81.                     if j % 2 == 0 then
  82.                         turnRight()
  83.                     else
  84.                         turnLeft()
  85.                     end
  86.                 end
  87.             end
  88.             j = j + 1
  89.         end
  90.         local l = 1
  91.         while l < distanceFront do
  92.             print(l)
  93.             robot.swing()
  94.             if robot.forward() then
  95.                 l = l + 1
  96.             end
  97.         end
  98.         if k == (distanceDown - 1) then
  99.             print("ENDING")
  100.             purge()
  101.             gen.remove()
  102.             computer.shutdown(false)
  103.         end
  104.         purge()
  105.         robot.swingDown()
  106.         robot.down()
  107.         robot.turnAround()
  108.         changeDirection()
  109.         k = k + 1
  110.     end
  111. end
Add Comment
Please, Sign In to add comment