Advertisement
TechManDylan

ChatGPT MoveTo(X,Z) V0.2

Jan 6th, 2023
884
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.88 KB | None | 0 0
  1. function moveTo(x, z)
  2.   local currX, currZ = 0, 0
  3.   local facing = 0  -- 0 = north, 1 = east, 2 = south, 3 = west
  4.  
  5.   -- turn to face the positive X direction
  6.   while facing ~= 1 do
  7.     turtle.turnRight()
  8.     facing = (facing + 1) % 4
  9.   end
  10.  
  11.   -- move the turtle along the positive X axis until it reaches the target X coordinate
  12.   while currX ~= x do
  13.     if x > currX then
  14.       turtle.forward()
  15.       currX = currX + 1
  16.     else
  17.       turtle.back()
  18.       currX = currX - 1
  19.     end
  20.   end
  21.  
  22.   -- turn to face the positive Z direction
  23.   while facing ~= 0 do
  24.     turtle.turnRight()
  25.     facing = (facing + 1) % 4
  26.   end
  27.  
  28.   -- move the turtle along the positive Z axis until it reaches the target Z coordinate
  29.   while currZ ~= z do
  30.     if z > currZ then
  31.       turtle.forward()
  32.       currZ = currZ + 1
  33.     else
  34.       turtle.back()
  35.       currZ = currZ - 1
  36.     end
  37.   end
  38. end
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement