So when I do post it’s mostly just some really weird undebuggable stuff. Except every time I did end up debugging it. But here’s something I can’t debug: my creativity (lol)
Ok but seriously i’m having difficulty making a RLE system that scans patterns of multiple characters. Here is the problem (more like problem solving) i’m having:
A conventional RLE system only scans individual repeating characters. This type of RLE is very easy to code.
aaavvvvccccassss = 3a4v4ca4s
But let’s say we have a repeating pattern of characters. Without manually defining how long a pattern is how would one be able to
Specifically the problem i’m having is to find out what the pattern is. LALLAL could be the pattern, but LAL is just more efficient. I’m hoping you can give me a starting point to work upon.
(PS: I haven’t used regex or things like that before, so if this can be easily done with it please do tell me)
--Run length encode
--Found solution to my pattern length finding problems
--Amount pointer comes AFTER all of the data
--Please feed this functions LISTS
function encodingLibrary.RLEncode(itemTable: {any}) : string
table.insert(itemTable, "placeholderencode")
local finalString = ""
local currentFindingPattern = itemTable[1]
local lastFindingPattern = itemTable[1]
local repeatingPatterns = 0
for i, currentFindingPattern in pairs(itemTable) do
if currentFindingPattern == lastFindingPattern then
repeatingPatterns += 1
else
--if repeatingPatterns > 1 then
--this list's id is nothing to save on a bit of space
finalString ..= lastFindingPattern .. "{,".. encodingLibrary.ToHigherbase(repeatingPatterns) .."}"
--end
repeatingPatterns = 1
end
--print(currentFindingPattern, lastFindingPattern, repeatingPatterns, finalString)
lastFindingPattern = currentFindingPattern
end
return finalString
end
--Somehow made this work all in one run
function encodingLibrary.RLDecode(_string : string) : {any}
local finalTable = {}
local currentCharacter = ""
local currentString = ""
local tableType = ""
local repeatAmount = ""
local i = 0
--print(_string)
while i < string.len(_string) do
i += 1
currentCharacter = string.sub(_string, i, i)
--print(currentCharacter)
--print(tableType)
local contentateString = true
if currentCharacter == "{" then
if tableType == "justRepeat" then --There is only one data table for every item.
-- currentString ..= currentCharacter
end
tableType = "undefined"
elseif currentCharacter == "}" then
contentateString = false
currentString ..= currentCharacter
if tableType == "repeat" then
repeatAmount = encodingLibrary.Tobase10(repeatAmount)
currentString = string.sub(currentString, 1, string.len(currentString)-3-string.len(repeatAmount))
for i = 1, repeatAmount do
table.insert(finalTable, currentString)
end
repeatAmount = ""
currentString = ""
tableType = ""
end
elseif tableType == "undefined" then
if currentCharacter == "," then
tableType = "repeat"
else
tableType = "notRepeat"
end
elseif tableType == "repeat" then
repeatAmount ..= currentCharacter
end
if contentateString then
currentString ..= currentCharacter
end
end
return finalTable
end