Advertisement
Guest User

run

a guest
May 19th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. local position = vector.new(gps.locate(5))
  2. local home = vector.new(-265,101,8)
  3. local orientation = 0
  4.  
  5. local function turnleft()
  6.   orientation = orientation - 1
  7.   if orientation < -1 then orientation = 2 end
  8.   turtle.turnLeft()
  9. end
  10.  
  11. local function turnright()
  12.   orientation = orientation + 1
  13.   if orientation > 2 then orientation = -1 end
  14.   turtle.turnRight()
  15. end
  16.  
  17. local success = true
  18. local function forward()
  19.   if orientation == 0 then position.x = position.x - 1 end
  20.   if orientation == 2 then position.x = position.x + 1 end
  21.   if orientation == -1 then position.z = position.z - 1 end
  22.   if orientation == 1 then position.z = position.z + 1 end
  23.   success = turtle.forward()
  24. end
  25.  
  26. local function up()
  27.   position.y = position.y + 1
  28.   success = turtle.up()
  29. end
  30.  
  31. local funtion down()
  32.   position.y = position.y - 1
  33.   turtle.down()
  34. end
  35.  
  36. local function gohome()
  37.   while position.y < 120 then up() end
  38.   while orientation < 2 then turnright() end
  39.   while position.x < home.x then forward() end
  40.   turnright()
  41.   turnright()
  42.   while position.x > home.x then forward() end
  43.   turnright()
  44.   while position.z < home.z then forward() end
  45.   turnright()
  46.   turnright()
  47.   while position.z > home.z then forward() end
  48.   while position.y > 101 then down() end
  49.   turnright()
  50. end
  51.  
  52. local temp = vector.new(gps.location(5))
  53. local function findorient()
  54.   temp = vector.new(gps.location(5))
  55.   if forward then
  56.     position = vector.new(gps.location(5))
  57.     if position.x == temp.x then
  58.       if position.z > temp.z then orientation = 1
  59.       else
  60.       orientation = -1
  61.       end
  62.     else
  63.      if position.x > temp.x then orientation = 2
  64.      else
  65.      orientation = 0
  66.      end
  67.    else
  68.    up()
  69.    end    
  70. end
  71.  
  72. findorient()
  73. gohome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement