Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local cb = peripheral.find("chatBox")
- local srn = peripheral.wrap("top")
- local logFile = fs.open("log.txt", "a")
- local lines = {}
- while true do
- local event, username, message, uuid, isHidden = os.pullEvent("chat")
- -- Log the chat to a file
- logFile.writeLine(username .. ": " .. message)
- logFile.flush()
- -- Update the lines table with the new message
- table.insert(lines, username .. ": " .. message)
- if #lines > 15 then
- table.remove(lines, 1)
- end
- -- Clear the screen
- srn.clear()
- -- Display the chat on the monitor
- srn.setCursorPos(1, 1)
- for i = 1, #lines do
- srn.write(lines[i])
- srn.setCursorPos(1, i + 1)
- end
- end
- logFile.close()
Advertisement
Add Comment
Please, Sign In to add comment