Advertisement
SwellzD

robot

Aug 10th, 2022 (edited)
312
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. print("Please enter what this program runs through(turtle/tablet): ")
  2. local input = read()
  3. term.clear()
  4. print("Good")
  5.  
  6. -- tablet --
  7. if input == "tablet" then
  8.    
  9.     print("Please enter a communication channel from 2 to 65535(This channel must match the turtle channel): ")
  10.     local inputCHx = read()
  11.     term.clear()
  12.     print("Good")
  13.     local inputCH = inputCHx + 0
  14.     local modem = peripheral.wrap("back")
  15.  
  16.     while true do
  17.         local sEvent, param = os.pullEvent("key")
  18.         if sEvent == "key" then
  19.             modem.transmit(inputCH, (inputCH - 1), param)
  20.         end
  21.     end
  22. end
  23.  
  24. -- turtle --
  25. if input == "turtle" then
  26.    
  27.     print("Please enter a communication channel from 2 to 65535(This channel must match the tablet channel): ")
  28.     local inputCHx = read()
  29.     term.clear()
  30.     print("Good")
  31.     local inputCH = inputCHx + 0
  32.    
  33.     local modem = peripheral.wrap("right")
  34.  
  35.     while true do
  36.         modem.open(inputCH)
  37.         local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  38.         local key = message + 0
  39.        
  40.         if key == 87 then -- W --
  41.             turtle.forward()
  42.         elseif key == 65 then -- A --
  43.             turtle.turnLeft()
  44.         elseif key == 83 then -- S --
  45.             turtle.back()
  46.         elseif key == 68 then -- D --
  47.             turtle.turnRight()
  48.         elseif key == 81 then -- Q --
  49.             turtle.down()
  50.         elseif key == 69 then -- E --
  51.             turtle.up()
  52.         elseif key == 70 then -- F --
  53.             turtle.dig()
  54.         end
  55.     end
  56. end
  57.  
  58. print("Error")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement