Advertisement
TechManDylan

ChatGPT MoveTo(X,Z) V0.1

Jan 6th, 2023
942
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.77 KB | None | 0 1
  1. function moveTo(x, z)
  2.   local currX, currY, currZ = gps.locate()
  3.   if not currX then
  4.     print("Unable to get current location.")
  5.     return
  6.   end
  7.  
  8.   local diffX = x - currX
  9.   local diffZ = z - currZ
  10.  
  11.   if diffX > 0 then
  12.     turtle.turnRight()
  13.   elseif diffX < 0 then
  14.     turtle.turnLeft()
  15.   end
  16.  
  17.   while diffX ~= 0 do
  18.     if diffX > 0 then
  19.       turtle.forward()
  20.       diffX = diffX - 1
  21.     elseif diffX < 0 then
  22.       turtle.back()
  23.       diffX = diffX + 1
  24.     end
  25.   end
  26.  
  27.   if diffZ > 0 then
  28.     turtle.turnLeft()
  29.   elseif diffZ < 0 then
  30.     turtle.turnRight()
  31.   end
  32.  
  33.   while diffZ ~= 0 do
  34.     if diffZ > 0 then
  35.       turtle.forward()
  36.       diffZ = diffZ - 1
  37.     elseif diffZ < 0 then
  38.       turtle.back()
  39.       diffZ = diffZ + 1
  40.     end
  41.   end
  42. end
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement