I want to make a chatlog that admins can see. but what would be the most efficient way of storing it?
atm i use this bit of code
module.PlayerAdded = function(player)
player.Chatted:Connect(function(msg)
table.insert(chatlog,1,{tostring(os.time());player.Name.." ["..player.UserId.."]",msg})
if #chatlog>5000 then
chatlog[5001] = nil
end
end)
end
every time someone chats it puts the message on top of the table and if we pass 5000 entries it removes the last one
but it had me thinking… if i have 5000 entry`s it needs to move everything in the table 1 place down.
i could add it to the last entry and use table.flip() to get the latest. but at 5000 entries you get the same issue
local function CirculairBuffer (Table)
Table.index=0
local metatable = {}
metatable.__call=function (MyTable,Value)
MyTable.index += 1
if MyTable.index > 5000 then
MyTable.index = 1
end
MyTable[MyTable.index]=Value
end
setmetatable(Table,metatable)
end
There aren’t any issues I can see that might cause performance problems. You can do the index logic using % operator, don’t know if that’s faster than an if statement. Only way to know for sure is to test it.
Your implementation doesn’t have any ways of reading from the buffer, you’ll definitely need that.