Advertisement
DOGGYWOOF

Untitled

Oct 6th, 2024
2
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. -- Function to check for a modem and open Rednet
  2. local function setupRednet()
  3. local modemSide = nil
  4. for _, side in ipairs({"left", "right", "top", "bottom", "front", "back"}) do
  5. if peripheral.getType(side) == "modem" then
  6. modemSide = side
  7. break
  8. end
  9. end
  10.  
  11. if modemSide then
  12. rednet.open(modemSide) -- Open the modem on the detected side
  13. return true
  14. else
  15. print("No modem detected.")
  16. return false
  17. end
  18. end
  19.  
  20. local function sendCommand(command)
  21. rednet.broadcast(command)
  22. print("Command sent: " .. command)
  23. end
  24.  
  25. -- Initialize
  26. if setupRednet() then -- Check for modem and open Rednet
  27. -- Command input loop
  28. while true do
  29. print("Enter command (forward, backward, load, quit): ")
  30. local input = read()
  31. if input == "quit" then
  32. sendCommand("quit")
  33. break
  34. else
  35. sendCommand(input)
  36. end
  37. end
  38. else
  39. print("Exiting program.")
  40. end
  41.  
  42. rednet.close("left") -- Close the modem
  43.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement