Skip to content

Instantly share code, notes, and snippets.

@Achie72
Created February 12, 2020 18:11
Show Gist options
  • Save Achie72/50b84716ee33a3e76577acad7e72d5fd to your computer and use it in GitHub Desktop.
Save Achie72/50b84716ee33a3e76577acad7e72d5fd to your computer and use it in GitHub Desktop.
Pico-8 map string decoder
function parseMap(_mapString)
local mapString = _mapString
local actualMap = {}
while #mapString > 0 do
local firstToken=sub(mapString,1,1)
local cut = 2
if (firstToken!=",") then
local workString = sub(mapString,2)
local secondToken = sub(workString,1,1)
if (secondToken!=",") then
local workString = sub(mapString,3)
local thirdToken = sub(workString,1,1)
if (thirdToken!=",") then
local actualToken = firstToken..secondToken..thirdToken
add(actualMap,actualToken)
cut = 4
else
local actualToken = firstToken..secondToken
add(actualMap,actualToken)
cut = 3
end
else
add(actualMap,firstToken)
cut = 2
end
end
mapString=sub(mapString,cut)
end
return actualMap
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment