Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Initialize rednet
- local modemSide = "right" -- Adjust side based on where your modem is attached
- rednet.open(modemSide)
- print("Enter the ID of the computer you want to message:")
- local targetID = tonumber(read())
- if not targetID then
- print("Invalid computer ID.")
- return
- end
- print("Connected to computer " .. targetID)
- -- Function to send messages
- local function sendMessage(targetID)
- while true do
- print("Type your message: ")
- local message = read()
- rednet.send(targetID, message)
- print("Message sent to " .. targetID)
- end
- end
- -- Function to receive messages
- local function receiveMessage()
- while true do
- local senderID, message, protocol = rednet.receive()
- if senderID == targetID then
- print("Message from " .. senderID .. ": " .. message)
- end
- end
- end
- -- Run sendMessage and receiveMessage functions simultaneously
- parallel.waitForAny(sendMessage, receiveMessage, targetID)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement