Guest User

movearound

a guest
Mar 12th, 2013
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. rednet.open ("right")
  2. PCID = 21
  3.  
  4. orientation = 1
  5. orientations = {"north", "east", "south", "west"}
  6.  
  7. xCoord = 0
  8. zCoord = 0
  9. yCoord = 0
  10.  
  11. zDiff = {-1, 0, 1, 0}
  12. xDiff = {0, 1, 0, -1}
  13.  
  14. local function left()
  15.     orientation = orientation - 1
  16.     orientation = (orientation - 1) % 4
  17.     orientation = orientation + 1
  18.     turtle.turnLeft()
  19. end
  20.  
  21.  
  22. local function right()
  23.     orientation = orientation - 1
  24.     orientation = (orientation + 1) % 4
  25.     orientation = orientation + 1
  26.     turtle.turnRight()
  27. end
  28.  
  29.  
  30. local function moveForward()
  31.     xCoord = xCoord + xDiff[orientation]  
  32.     zCoord = zCoord + zDiff[orientation]
  33.     while turtle.detect() do
  34.     turtle.dig()
  35.     end
  36.     moved = false
  37.     while not(moved) do
  38.         moved = turtle.forward()
  39.     end
  40. end
  41.  
  42.  
  43. local function moveUp()
  44.     yCoord = yCoord + 1
  45.     turtle.digUp()
  46.     moved = false
  47.     while not(moved) do
  48.         moved = turtle.up()
  49.     end
  50. end
  51.  
  52.  
  53. local function moveDown()
  54.     yCoord = yCoord - 1
  55.     turtle.digDown()
  56.     moved = false
  57.     while not(moved) do
  58.         moved = turtle.down()
  59.     end
  60. end
  61.  
  62. local function moveBack()
  63.  left()
  64.  left()
  65.  moveForward()
  66.  left()
  67.  left()
  68. end
  69.  
  70.  
  71. local function checkorder(command)
  72.  if command == "go" then
  73.     moveForward()
  74.  
  75.   elseif command == "back" then
  76.     moveBack()
  77.  
  78.   elseif command == "left" then
  79.     left()
  80.  
  81.   elseif command == "right" then
  82.     right()
  83.  
  84.   elseif command == "dig" then
  85.     turtle.dig()
  86.  
  87.   elseif command == "up" then
  88.     moveUp()
  89.  
  90.   elseif command == "down" then
  91.     moveDown()
  92.    
  93.   elseif command == "place" then
  94.     turtle.place()
  95.  
  96.   elseif command == "digup" then
  97.     turtle.digUp()
  98.  
  99.   elseif command == "digdown" then
  100.     turtle.digDown()
  101.    
  102.   elseif command == "placeup" then
  103.     turtle.placeUp()
  104.    
  105.   elseif command == "placedown" then
  106.     turtle.placeDown()
  107.   end
  108.   end
  109.  
  110. while true do
  111. id, com = rednet.receive()
  112. checkorder(com)
  113. sleep(1)
  114. print("I am at X: " ..xCoord.. " Z: " ..zCoord.. "Y " ..yCoord)
  115. end
Advertisement
Add Comment
Please, Sign In to add comment