Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local chatLog = {} -- Table to store chat messages
- local maxMessages = 10 -- Maximum number of messages to display at once
- local startIndex = 1 -- Starting index for displaying chat messages
- local function printChatMessages()
- term.clear()
- term.setCursorPos(1, 1)
- print("=== Chat Log ===")
- for i = startIndex, math.min(#chatLog, startIndex + maxMessages - 1) do
- print(chatLog[i])
- end
- print("Press 'Q' to exit. Use Up/Down arrows to scroll.")
- end
- while true do
- local event, p1, p2, p3, p4, p5 = os.pullEvent()
- if event == "chat" then
- local username = p2
- local message = p3
- table.insert(chatLog, username .. ": " .. message) -- Log the chat message
- printChatMessages() -- Print the updated chat log
- elseif event == "key" then
- if p1 == keys.q then
- break -- Exit the program if 'Q' key is pressed
- elseif p1 == keys.up then
- startIndex = math.max(1, startIndex - 1) -- Scroll up
- printChatMessages()
- elseif p1 == keys.down then
- startIndex = math.min(#chatLog - maxMessages + 1, startIndex + 1) -- Scroll down
- printChatMessages()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement