Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. local function move(direction, increment)
  2. local switch = {
  3. ['up'] = function()
  4. for i=1,increment,1 do turtle.up() end
  5. end,
  6. ['down'] = function()
  7. for i=1,increment,1 do turtle.down() end
  8. end,
  9. ['forward'] = function()
  10. for i=1,increment,1 do turtle.forward() end
  11. end,
  12. ['right'] = function()
  13. for i=1,increment,1 do turtle.back() end
  14. end
  15. }
  16.  
  17. local f = switch[direction]
  18. if(f) then
  19. f()
  20. else -- for case default
  21. print "Defaulted."
  22. end
  23. end
  24.  
  25. local function rotate(direction)
  26. local switch = {
  27. ['left'] = function()
  28. turtle.turnLeft()
  29. end,
  30. ['right'] = function()
  31. turtle.turnRight()
  32. end
  33. }
  34.  
  35. local f = switch[direction]
  36. if(f) then
  37. f()
  38. else -- for case default
  39. print "Defaulted."
  40. end
  41. end
  42.  
  43. local function place(slot, text)
  44. turtle.select(slot)
  45. turtle.place(text)
  46. end
  47.  
  48. local function dig(direction)
  49.  
  50. local switch = {
  51. ['up'] = function()
  52. turtle.digUp()
  53. end,
  54. ['forward'] = function()
  55. turtle.dig()
  56. end,
  57. ['down'] = function()
  58. turtle.digDown()
  59. end
  60. }
  61. local f = switch[direction]
  62. if(f) then
  63. f()
  64. else -- for case default
  65. print "Defaulted."
  66. end
  67. end
  68.  
  69. function operation(optype, direction, slot, text, increment)
  70. direction = direction or ''
  71. slot = slot or ''
  72. text = text or ''
  73. increment = increment or ''
  74. local switch = {
  75. ['dig'] = function()
  76. dig(direction)
  77. end,
  78. ['move'] = function()
  79. move(direction, tonumber(increment))
  80. end,
  81. ['rotate'] = function()
  82. rotate(direction)
  83. end,
  84. ['place'] = function()
  85. place(tonumber(slot), text)
  86. end
  87. }
  88. local f = switch[optype]
  89. if(f) then
  90. f()
  91. else -- for case default
  92. print "Defaulted."
  93. end
  94. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement