Stevemine26

turtle_interface

Jul 7th, 2025
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. -- turtle_client
  2. rednet.open("back") -- Adjust as needed
  3. print("Turtle Controller (Pocket Computer)")
  4. print("Enter turtle ID (or 'scan' to search):")
  5.  
  6. local idInput = read()
  7. local turtleID
  8.  
  9. if idInput == "scan" then
  10.     print("Scanning for turtle...")
  11.     local id = rednet.lookup("turtle", nil)
  12.     if id then
  13.         print("Found turtle with ID:", id)
  14.         turtleID = id
  15.     else
  16.         print("No turtles found.")
  17.         return
  18.     end
  19. else
  20.     turtleID = tonumber(idInput)
  21. end
  22.  
  23. print("Available commands:")
  24. print("- Movement: forward, back, left, right, up, down (movement amount)")
  25. print("- dig, place (up/down/forward)")
  26. print("- select/slot <1-15>")
  27. print("- exit")
  28.  
  29. while true do
  30.     term.write("> ")
  31.     local input = read()
  32.  
  33.     if input ~= "disconnect" then rednet.send(turtleID, input) end
  34.     if input == "exit" then
  35.         print("Sent shutdown command.")
  36.         break
  37.     end
  38.     if input == "disconnect" then
  39.         print("Disconnecting")
  40.         break
  41.     end
  42.     local sender, response = rednet.receive(2) -- wait up to 2 seconds for reply
  43.     if response then
  44.         print("< " .. response)
  45.     else
  46.         print("< No Response.")
  47.     end
  48. end
  49.  
Tags: Cc
Advertisement
Add Comment
Please, Sign In to add comment