Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local username = "Not set"
- local channel = "Not set"
- local modem = peripheral.wrap("top")
- function topBar()
- term.setCursorPos(1,1)
- term.clearLine()
- print("oChat v 1.0")
- term.clearLine()
- print("User: "..username..", Channel: "..channel)
- end
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- print("oChat v 1.0")
- print("User: "..username..", Channel: "..channel)
- end
- function setChannel()
- clearScreen()
- write("Channel number (1-100): ")
- local channelInput = tonumber(read())
- if (channelInput < 1) or (channelInput > 100) then
- print("Invalid channel...")
- sleep(1)
- setChannel()
- else
- channel = channelInput
- end
- end
- clearScreen()
- write("Enter a username: ")
- username = read()
- setChannel()
- modem.open(channel)
- function receive()
- local event,modemSide,senderChannel,replyChannel,message,distance = os.pullEvent("modem_message")
- term.clearLine()
- if not (string.match(message, username)) then
- print(message)
- topBar()
- end
- end
- function send()
- term.setCursorPos(1,19)
- write("> ")
- local message = read()
- modem.transmit(channel,1,"<"..username.."> "..message)
- topBar()
- end
- clearScreen()
- while true do
- parallel.waitForAny(receive, send)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement