Advertisement
MonotoneDev

CC:Tweaked ChatApp

Apr 5th, 2024 (edited)
664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.93 KB | Software | 0 0
  1. -- Get the username and channel
  2. write("Username: ")
  3. username = read()
  4. write("Channel: ")
  5. channel = read()
  6.  
  7. term.clear()
  8. term.setCursorPos(1,1)
  9.  
  10. -- Open any modems on the computer
  11. peripheral.find("modem", rednet.open)
  12. message = ""
  13.  
  14. -- Creates a window in the terminal for the chat
  15. termX, termY = term.getSize()
  16.  
  17.  
  18. -- Recieves chat messages from other clients on the same channel
  19. function receiveChat()
  20.     print()
  21.     print(rednet.receive(channel))
  22. end
  23.  
  24. -- Sends messages to other clients on the same channel
  25. function sendMsg()
  26.     while true do
  27.         write(">: ")
  28.         message = read()
  29.         if message == "exit[]" then
  30.             os.reboot()
  31.         end
  32.         term.clearLine()
  33.         rednet.broadcast(username..": '"..message.."', on ", channel)
  34.     end
  35. end
  36.  
  37. -- Runs the functions in parallel so you can recieve and send messages at the same time
  38. while true do
  39.     parallel.waitForAny(receiveChat, sendMsg)
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement