Advertisement
Wassaa

Robot tests

Mar 6th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. local robot = require("robot")
  2. local component = require("component")
  3. side = require("sides")
  4. inv = component.inventory_controller
  5. -- 0 = nothing, 1 = shift place, 2 = swing
  6.  
  7. function putInAnlzer()
  8.     robot.dropUp()
  9. end
  10.  
  11. function takeFromAnlzer()
  12.     inv.suckFromSlot(1,1)
  13.     robot.select(1)
  14. end
  15.  
  16. function checkCount(slot)
  17.     itemInfo = inv.getStackInInternalSlot(slot)
  18.     if itemInfo ~= nil and itemInfo.size == 1 then
  19.         return true
  20.     end
  21.     return false
  22. end
  23.  
  24. local function forward(times,action)
  25.   times = times or 1
  26.   for i = 1, times do
  27.     robot.forward()
  28.     if action == 1 then
  29.         robot.placeDown(0,true)
  30.     elseif action == 2 then
  31.         robot.swingDown()
  32.     end
  33.   end
  34. end
  35.  
  36.  
  37. local function getSeed()
  38.     robot.turnRight()
  39.     robot.select(2)
  40.     robot.suck()
  41.     robot.select(1)
  42.     robot.turnLeft()
  43. end
  44. local function plant()
  45.     robot.select(1)
  46.     robot.placeDown()
  47.     robot.select(2)
  48.     inv.equip()
  49.     robot.useDown()
  50.     inv.equip()
  51.     robot.select(1)
  52.     forward(6,1)
  53.     robot.turnRight()
  54.     forward(6,1)
  55.     robot.turnRight()
  56.     forward(6,1)
  57.     robot.turnRight()
  58.     forward(2,1)
  59.     robot.turnRight()
  60.     forward(4,1)
  61.     robot.turnLeft()
  62.     forward(2,1)
  63.     robot.turnLeft()
  64.     forward(4,1)
  65.     robot.turnAround()
  66.     forward(1)
  67.     robot.turnLeft()
  68.     forward(2)
  69.     robot.turnRight()
  70.     robot.back()
  71. end
  72.  
  73. local function collect()
  74.     robot.swingDown()
  75.     forward(6,2)
  76.     robot.turnRight()
  77.     forward(6,2)
  78.     robot.turnRight()
  79.     forward(6,2)
  80.     robot.turnRight()
  81.     forward(2,2)
  82.     robot.turnRight()
  83.     forward(4,2)
  84.     robot.turnLeft()
  85.     forward(2,2)
  86.     robot.turnLeft()
  87.     forward(3,2)
  88.     robot.forward()
  89.    
  90.     for i=2,robot.inventorySize() do
  91.         robot.select(i)
  92.         robot.drop()
  93.     end
  94.     robot.select(1)
  95.    
  96.     robot.swingDown()
  97.     for i=2,robot.inventorySize() do
  98.         if checkCount(i) then
  99.             robot.select(i)
  100.             putInAnlzer()
  101.             break
  102.         end
  103.     end
  104.     os.sleep(6)
  105.     takeFromAnlzer()
  106.     robot.select(1)
  107.     robot.turnAround()
  108.     forward(1)
  109.     robot.turnLeft()
  110.     forward(2)
  111.     robot.turnRight()
  112.     robot.back()
  113. end
  114.  
  115. local function dumpAll()
  116.     robot.turnAround()
  117.     for i=1,robot.inventorySize() do
  118.         robot.select(i)
  119.         robot.drop()
  120.     end
  121.     robot.turnAround()
  122.     robot.select(1)
  123. end
  124.  
  125. local function getSticks()
  126.     robot.turnLeft()
  127.     robot.select(1)
  128.     robot.suck()
  129.     robot.turnRight()
  130. end
  131.  
  132. while true do
  133.     itemInfo = inv.getStackInInternalSlot(2)
  134.     if itemInfo ~= nil then
  135.         plant()
  136.         os.sleep(120)
  137.         collect()
  138.         dumpAll()
  139.         getSticks()
  140.         getSeed()
  141.     else
  142.         print("Waiting for Seeds")
  143.         os.sleep(5)
  144.         getSeed()
  145.     end
  146. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement