Advertisement
M1cksta

Untitled

Mar 20th, 2025
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.26 KB | None | 0 0
  1. function Move(direction, steps)
  2.     if direction == "frwd" then
  3.         for i= 1, steps, 1 do
  4.             turtle.forward()
  5.         end
  6.     elseif direction == "back" then
  7.         for i= 1, steps, 1 do
  8.             turtle.back()
  9.         end
  10.     elseif direction == "up" then
  11.         for i = 1, steps, 1 do
  12.             turtle.up()
  13.         end
  14.     elseif direction == "down" then
  15.         for i = 1, steps, 1 do
  16.             turtle.down()
  17.         end
  18.     else
  19.         error("err: invalid direction")
  20.     end
  21. end
  22.  
  23. function Turn(direction, steps)
  24.     if direction == "left" then
  25.         for i = 1, steps, 1 do
  26.             turtle.turnLeft()
  27.         end
  28.     elseif direction == "right" then
  29.         for i = 1, steps, 1 do
  30.             turtle.turnRight()
  31.         end
  32.     else
  33.         error("err: invalid direction")
  34.     end
  35. end
  36.  
  37. local modem = peripheral.wrap("left")
  38. modem.open(1)
  39.  
  40. while true do
  41.     local event,
  42.     modemSide,
  43.     senderChannel,
  44.     replyChannel,
  45.     message,
  46.     senderDistance = os.pullEvent("modem_message")
  47.  
  48.     if message == "end" then
  49.         break
  50.     elseif message == "frwd" then
  51.         Move("frwd", 1)
  52.     elseif message == "back" then
  53.         Move("back", 1)
  54.     else
  55.         error("err: invalid command")
  56.     end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement