I added a removemessage function into the lua chat that lets me remove a message from the chat given the message's text. This works fine for the most part but I realised that after a while the chat just.. died. All messages had disappeared and any messages players sent wouldn't appear either.
After a few hours of trying to figure out why they were disappearing I found out that I was only removing the messages from the MessageDisplayLog and not the MessageLog, meaning that once the MessageLog reached the maximum amount, it would start removing the last message from the chat.
So, inside ChatScript.ChatMain.ChatChannel I modified my RemoveMessage function to have a loop to remove the message from the messagelog while also calling the function inside MessageLogDisplay to actually remove the message from the chat.
function methods:RemoveMessage(messageData)
self.MessageLogDisplay:RemoveMessage(messageData)
local int=0
print(#self.MessageLog)
for _, v in pairs(self.MessageLog) do
int=int+1
if(v.Message:gsub("%s+","")==messageData:gsub("%s+","")) then
table.remove(self.MessageLog,int)
end
end
print(#self.MessageLog)
end
I also added some sanity check print statements before and after the loop. First print statement before the loop prints 1 (this is just testing with one message in the chat at the time) and the print statement after the loop prints 0 meaning it has successfully removed the message from the log. (also, the way I use this function is so that every time I send a system message, I can remove the old one so the chat doesn't get cluttered with them)
So I tested the game, and still the messages disappeared after a while. What? So I then added a print statement to this function to also check the length of MessageLog
function methods:AddMessageToChannel(messageData)
table.insert(self.MessageLog, messageData)
if self.Active then
self.MessageLogDisplay:AddMessage(messageData)
end
if #self.MessageLog > ChatSettings.MessageHistoryLengthPerChannel then
self:RemoveLastMessageFromChannel()
end
print("!!",#self.MessageLog)
end
and in here, messagelog is continuously rising. Why? I'm not adding any messages except for 1 system message which also being removed as proven by my RemoveMessage function.
If anyone can shed some light on why this is occuring, that would be great.
