Advertisement
Guest User

moveto

a guest
Apr 1st, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.18 KB | None | 0 0
  1. local tArgs = {...}
  2. local args1 = tonumber(tArgs[1])
  3. local args2 = tonumber(tArgs[2])
  4. local args3 = tonumber(tArgs[3])
  5.  
  6. local cDir = "north"
  7. local cY = 0
  8. local cX = 0
  9. local cZ = 0
  10. local blocks = "blocks"
  11.  
  12. function turnRight()
  13.   if cDir == "north" then
  14.     cDir = "east"
  15.   elseif cDir == "east" then
  16.     cDir = "south"
  17.   elseif cDir == "south" then
  18.     cDir = "west"
  19.   elseif cDir == "west" then
  20.     cDir = "north"
  21.   else
  22.     print("Error!!")
  23.   end
  24.   turtle.turnRight()
  25. end
  26.  
  27.  
  28. function turnTo(dir)
  29.   if cDir ~= dir then
  30.     repeat
  31.      turnRight()
  32.     until cDir == dir
  33.   end
  34. end
  35.  
  36. function moveForward()
  37.   if cDir == "north" then
  38.     cX = cX+1
  39.   elseif cDir == "east" then
  40.     cZ = cZ+1
  41.   elseif cDir == "south" then
  42.     cX = cX-1
  43.   elseif cDir == "west" then
  44.     cZ = cZ-1
  45.   else
  46.     print("Error!!")
  47.   end
  48.   while not turtle.forward() do
  49.     turtle.dig()
  50.   end
  51. end
  52.  
  53. function moveUp()
  54.   cY = cY+1
  55.   while not turtle.up() do
  56.     turtle.digUp()
  57.   end
  58. end
  59.  
  60. function moveDown()
  61.   cY = cY-1
  62.   while not turtle.down() do
  63.     turtle.digDown()
  64.   end
  65. end
  66.    
  67. function moveToX(x)
  68.   if cX < x then
  69.     turnTo("north")
  70.     repeat
  71.       moveForward()
  72.     until cX == x
  73.   elseif cX > x then
  74.     turnTo("south")
  75.     repeat
  76.       moveForward()
  77.     until cX == x
  78.   else
  79.     --print("already there")
  80.   end
  81. end
  82.  
  83. function moveToZ(z)
  84.   if cZ < z then
  85.     turnTo("east")
  86.     repeat
  87.       moveForward()
  88.     until cZ == z
  89.   elseif cZ > z then
  90.     turnTo("west")
  91.     repeat
  92.       moveForward()
  93.     until cZ == z
  94.   else
  95.    --print("already there")
  96.   end
  97. end    
  98.  
  99. function moveToY(y)
  100.   if cY < y then
  101.     repeat
  102.       moveUp()
  103.     until cY == y
  104.   elseif cY > y then
  105.     repeat
  106.       moveDown()
  107.     until cY == y
  108.   else
  109.    --print("already there")
  110.   end
  111. end
  112.  
  113. function goTo(x, y, z)
  114.   moveToX(x)  
  115.   moveToY(tonumber(y))
  116.   moveToZ(tonumber(z))
  117.   turnTo("north")
  118. end
  119.  
  120. function sayMoveX()
  121.   if args1 == 1 or args1 == -1 then
  122.     blocks = "block"
  123.   else
  124.     blocks = "blocks"
  125.   end
  126.   if args1 > 0 then
  127.     print("I have moved "..tArgs[1].." "..blocks.." forward.")
  128.   elseif args1 < 0 then
  129.   local x = args1*-1
  130.     print("I have moved "..x.." "..blocks.." backwards.")
  131.   else
  132.     print("I haven't moved forward or backwards.")
  133.   end
  134. end
  135.  
  136. function sayMoveY()
  137.   if args2 == 1 or args2 == -1 then
  138.     blocks = "block"
  139.   else
  140.     blocks = "blocks"  
  141.   end
  142.   if args2 > 0 then
  143.     print("I have moved "..args2.." "..blocks.." up.")
  144.   elseif args2 < 0  then
  145.   local y = args2*-1
  146.     print("I have moved "..y.." "..blocks.." down.")
  147.   else
  148.     print("I haven't moved up or down.")          
  149.   end
  150. end
  151.  
  152. function sayMoveZ()
  153.   if args3 == 1 or args3 == -1 then
  154.     blocks = "block"
  155.   else
  156.     blcoks = "blocks"
  157.   end
  158.   if args3 > 0 then
  159.     print("I have moved "..args3.." "..blocks.." to the right.")
  160.   elseif args3 < 0 then
  161.   local z = args3*-1
  162.     print("I have moved "..z.." "..blocks.." to the left.")
  163.   else
  164.     print("I haven't moved to the right or left.")
  165.   end
  166. end
  167.  
  168. function sayMoves()
  169.   sayMoveX()
  170.   sayMoveY()
  171.   sayMoveZ()
  172. end      
  173.                                  
  174. goTo(args1,args2,args3)
  175. sayMoves()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement