Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to check for a modem and open Rednet
- local function setupRednet()
- local modemSide = nil
- for _, side in ipairs({"left", "right", "top", "bottom", "front", "back"}) do
- if peripheral.getType(side) == "modem" then
- modemSide = side
- break
- end
- end
- if modemSide then
- rednet.open(modemSide) -- Open the modem on the detected side
- return true
- else
- print("No modem detected.")
- return false
- end
- end
- local function sendCommand(command)
- rednet.broadcast(command)
- print("Command sent: " .. command)
- end
- -- Initialize
- if setupRednet() then -- Check for modem and open Rednet
- -- Command input loop
- while true do
- print("Enter command (forward, backward, load, quit): ")
- local input = read()
- if input == "quit" then
- sendCommand("quit")
- break
- else
- sendCommand(input)
- end
- end
- else
- print("Exiting program.")
- end
- rednet.close("left") -- Close the modem
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement