Sir_Popsilots

turtle_clientV2

Jun 28th, 2021 (edited)
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. local modem = peripheral.find("modem")
  2. local WasSent = false
  3. modem.open(42069)
  4. local PrintTable = {"The turtle moved forwards",
  5.                     "The turtle moved backwards",
  6.                     "The turtle turned left",
  7.                     "The turtle turned right",
  8.                     "The turtle went down",
  9.                     "The turtle went up"}
  10. local FalsePrintTable = {"The turtle couldn't move forwards",
  11.                          "The turtle couldn't move backwards",
  12.                          "LOL","XD uwu",
  13.                          "The turtle couldn't go down",
  14.                          "The turtle couldn't go up"}
  15. local TransTable = {'w','s','a','d','q','e'}
  16. local function MoveThere(char)
  17.     print("was in MoveThere")
  18.     if char == 'w' then
  19.         turtle.forward()
  20.     elseif char == 's' then
  21.         turtle.back()
  22.     elseif char == 'a' then
  23.         turtle.turnLeft()
  24.     elseif char == 'd' then
  25.         turtle.turnRight()
  26.     elseif char == 'q' then
  27.         turtle.down()
  28.     elseif char == 'e' then
  29.         turtle.up()
  30.     end
  31. end
  32.  
  33. local function CheckIfCanMove(char)
  34.     print("was in Check")
  35.     if char == 'w' and turtle.forward() then
  36.         return true
  37.     elseif char == 's' and turtle.back()  then
  38.         return true
  39.     elseif char == 'q' and turtle.down()  then
  40.         return true
  41.     elseif char == 'e' and turtle.up()  then
  42.         return true
  43.     else
  44.         return false
  45.     end
  46. end
  47.  
  48. while true do
  49.     local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  50.     if message == "break" then
  51.         break
  52.     end
  53.     WasSent = false
  54.     for i = 1, 6, 1 do
  55.          if message == TransTable[i] then
  56.             if i == 1 or i==2 or i == 5 or i == 6 then
  57.                 if CheckIfCanMove(message) then
  58.                     modem.transmit(42069, 42069, PrintTable[i])
  59.                 else
  60.                     modem.transmit(42069, 42069, FalsePrintTable[i])
  61.                 end
  62.             else
  63.                 MoveThere(message)
  64.                 modem.transmit(42069, 42069, PrintTable[i])
  65.             end
  66.             WasSent = true
  67.             break
  68.         end
  69.     end
  70.     if WasSent == false then
  71.         modem.transmit(42069, 42069, "Error")
  72.     end
  73. end
  74. if turtle.detectDown() == false then
  75.     while turtle.detectDown() == false do
  76.         turtle.down()
  77.     end
  78. end
  79. modem.close(42069)
Add Comment
Please, Sign In to add comment