I want to create a Counter Strike 1.6 style chat system where only 4 recent messages are shown in the screen and everytime a new message arrives the messages move up and the new message is shown in the bottom.

I can’t find a way to store only 4 messages in a table and when the 5th message arrives move all the elements up 1 position so the first message is removed and the last message is inserted in the end of the table.
so far my code…
local msgs = {}
local number = 1
local message = "message "…number
number = number + 1
local function newMessageEvent(player, msg)
msgs[player]=msg
for i, v in pairs(msgs) do
print(i, v)
end
print("--------------------")
end
local button = display.newCircle( 100, 100, 35 )
button:addEventListener ( “tap”, newMessageEvent(“bob”,message)
