Advertisement
Volaik

slave

Nov 12th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local CLIENT_PORT = 0
  2. local SERVER_PORT = 1544
  3.  
  4. local modem = peripheral.find("")
  5. modem.open(SERVER_PORT)
  6.  
  7. print("I am listening to channel "..SERVER_PORT)
  8.  
  9. while true do
  10. local event, modemSide, senderChannel, replyChannel, message, distance = os.pullEvent("modem_message")
  11.  
  12. local x, y, z = gps.locate(5)
  13.  
  14. if message == "w" then
  15.         turtle.forward()
  16.     elseif message == "s" then
  17.         turtle.back()
  18.     elseif message == "a" then
  19.         turtle.turnLeft()
  20.     elseif message == "d" then
  21.         turtle.turnRight()
  22.     elseif message == "u" then
  23.         turtle.up()
  24.     elseif message == "do" then
  25.         turtle.down()
  26.     elseif message == "locate" then
  27.         if not x then
  28.             modem.transmit(CLIENT_PORT, SERVER_PORT, "Failed to get my location!")
  29.         else
  30.             modem.transmit(CLIENT_PORT, SERVER_PORT, "I am at (" .. x .. ", " .. z .. ", " .. y .. ")")
  31.         end
  32.     end
  33. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement