Advertisement
guitarplayer616

GPS self tracking API

Apr 25th, 2015
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.64 KB | None | 0 0
  1. local xPos, yPos, zPos = nil
  2. face = 1
  3. cal = false
  4.  
  5. function setLocation() -- get gps using other computers
  6.  xPos, yPos, zPos = gps.locate()
  7.  cal = true
  8. end
  9.  
  10. function manSetLocation(number x, number y, number z) -- manually set location
  11.  xPos = x
  12.  yPos = y
  13.  zPos = z
  14.  cal = true
  15. end
  16.  
  17. function getLocation() -- return the location
  18.  if xPos != nil then
  19.   return xPos, yPos, zPos
  20.  elseif xPos == nil then
  21.   return nil
  22.  end
  23. end
  24.  
  25. function turnLeft() -- turn left
  26.  if face == 0 then
  27.   face = 1
  28.  elseif face == 1 then
  29.   face = 2
  30.  elseif face == 2 then
  31.   face = 3
  32.  elseif face == 3 then
  33.   face = 0
  34.  end
  35. end
  36.  
  37. function turnRight() -- turn right
  38.  if face == 0 then
  39.   face = 3
  40.  elseif face == 1 then
  41.   face = 0
  42.  elseif face == 2 then
  43.   face = 1
  44.  elseif face == 3 then
  45.   face = 2
  46.  end
  47. end
  48.  
  49. function forward() -- go forward
  50.  turtle.forward()
  51.  if cal == true then
  52.   if face == 0 then
  53.    zPos = zPos - 1
  54.   elseif face == 1 then
  55.    xPos = xPos - 1
  56.   elseif face == 2 then
  57.    zPos = zPos + 1
  58.   elseif face == 3 then
  59.    xPos = xPos + 1
  60.   end
  61.  else
  62.   print("Not Calibrated.")
  63.  end
  64. end
  65.  
  66. function back() -- go back
  67.  turtle.back()
  68.  if cal == true then
  69.   if face == 0 then
  70.    zPos = zPos + 1
  71.   elseif face == 1 then
  72.    xPos = xPos + 1
  73.   elseif face == 2 then
  74.    zPos = zPos - 1
  75.   elseif face == 2 then
  76.    xPos = xPos - 1
  77.   end
  78.  else
  79.   print("Not Calibrated.")
  80.  end
  81. end
  82.  
  83. function up() -- go up
  84.  turtle.up()
  85.  if cal == true then
  86.   yPos = yPos + 1
  87.  else
  88.   print("Not Calibrated.")
  89.  end
  90. end
  91.  
  92. function down() -- go down
  93.  turtle.down()
  94.  if cal == true then
  95.   yPos = yPos - 1
  96.  else
  97.   print("Not Calibrated.")
  98.  end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement