rjtwins

MC_OOC_Robot_test

Aug 30th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.72 KB | None | 0 0
  1. print("Starting robot test script")
  2. --init vars--
  3. local component = require("component")
  4. local sides = require("sides")
  5. local term = require("term")
  6. local robot = require("robot")
  7. local geo = component.geolyzer
  8. local inv = component.inventory_controller
  9.  
  10. --util func--
  11. function itenInSlot (n)
  12.     return inv.getStackInInternalSlot(n).name
  13. end
  14.  
  15. function getDownName ()
  16.     return geo.analyze(sides.down).name
  17. end
  18.  
  19. --program vars--
  20. local i_for = itenInSlot(1)
  21. local i_bac = itenInSlot(2)
  22. local i_rot_r = itenInSlot(3)
  23. local i_rot_l = itenInSlot(4)
  24. local i_rot_180 = itenInSlot(5)
  25. local i_pause = itenInSlot(6)
  26. local i_break = itenInSlot(7)
  27.  
  28. --functions--
  29. function f_until_stop()
  30.     robot.forward()
  31.     while true do
  32.         b = getDownName()
  33.         if b == i_bac or b == i_up or b == i_dow or b_== i_rot_r or b == i_rot_l or b == i_rot_180 or b == i_pause or b == i_break then
  34.             break
  35.         else
  36.             robot.forward()
  37.         end
  38.     end
  39. end
  40.  
  41. function b_until_stop()
  42.     robot.backward()
  43.     while true do
  44.         b = getDownName()
  45.         if b == i_for or b == i_up or b == i_dow or b_== i_rot_r or b == i_rot_l or b == i_rot_180 or b == i_pause or b == i_break then
  46.             break
  47.         else
  48.             robot.back()
  49.         end
  50.     end
  51. end
  52.  
  53. function main ()
  54.     for i=1,7,1 do
  55.          print(itenInSlot(i))
  56.     end
  57.     while true do
  58.         b = getDownName()
  59.         term.clear()       
  60.         print("Down block was: ", b)
  61.         if b == i_for then
  62.             f_until_stop()
  63.         elseif b == i_bac then
  64.             b_until_stop()
  65.         elseif b == i_rot_r then
  66.             robot.turnRight()
  67.             f_until_stop()
  68.         elseif b == i_rot_l then
  69.             robot.turnLeft()
  70.             f_until_stop()
  71.         elseif b == i_rot_180 then
  72.             robot.turnAround()
  73.             f_until_stop()
  74.         elseif b == i_pause then
  75.             os.sleep(1)
  76.         elseif b == i_break then break
  77.         end
  78.     end
  79. end
  80.  
  81. main()
Add Comment
Please, Sign In to add comment