Here is a MUD that has a map made of text. I've placed it in a table called
sys.map_table:
sys.map_table = {
"??????????????????????????????$$$$$$$ ??????????????????????????????",
"?????????????????????????? $$$$$$$$$$ ??????????????????????????",
"??????????????????????? $$$$$$$$$$ ???????????????????????",
"???????????????????? $$$$$$$$$$ 0????????????????????",
"?????????????????? 0 $$$$$$$$$$ 0 0??????????????????",
"????????????????? $$$$$$$$$$ ?????????????????",
"??????????????? 0 $$$$$$$$$$ ???????????????",
"?????????????? 0 $$$$$$$$$$ ??????????????",
"????????????? $$$$$$$$$$ 0 0 ?????????????",
"???????????? 0 0 0 ????????????",
"?????????? 00 0 0 ??????????",
"?????????? 0 0 0 0??????????",
"????????? 0 N D ?????????",
"???????? 0 0 0 ????????",
"??????? 0 ???????",
"?????? ??????",
"?????? N * * ??????",
"????? D * 0 00?????",
"???? * * M ????",
"???? B * D * 0 ????",
"??? * * ???",
"??? N * ???",
"??? 0 ???",
"?? * ??",
"?? 0 ??",
"?? 0 0 ??",
"? 0 D ?",
"? 0 0 ?",
"? ?",
"? * $$$$$$$$$$ ?",
" D D $$$$$$$$$$ ",
" * D* $$$$$$$$$$ ",
" O * $$$$$$$$$$ ",
" D M* O $$$$$$$$$$ ",
" 0 B M $$$$$$$$$$ ",
" D A H * $$$$$$$$$$ ",
" 0 * * D * $$$$$$$$$$ 0 ",
" * * * M $$$$$$$$$$ 0 0 ",
" * O M $$$$$$$$$$ ",
" 0 * ",
" * * ",
"? 0 0 M D * ?",
"? M ?",
"? 0 * M ?",
"? O ?",
"?? B N ??",
"?? 0 A * ??",
"?? 0 * ??",
"??? ???",
"??? $$$$$$$$$$ M ???",
"??? $$$$$$$$$$ D 0???",
"???? $$$$$$$$$$ * ????",
"???? 0 $$$$$$$$$$ 0 ????",
"????? 0 $$$$$$$$$$ ?????",
"?????? 0 MM$$$$$$$$$$ 0 ??????",
"?????? * $$$$$$$$$$ * ??????",
"??????? $$$$$$$$$$ ???????",
"???????? 0 $$$$$$$$$$ O 0 0 ????????",
"????????? 0 $$$$$$$$$$ ?????????",
"?????????? 00 0 ??????????",
"?????????? 0 0 ??????????",
"???????????? 0 0 0 0 ????????????",
"????????????? 0 0 ?????????????",
"?????????????? 0 ??????????????",
"??????????????? ???????????????",
"????????????????? 0 ?????????????????",
"?????????????????? 0 0 0 ??????????????????",
"???????????????????? 0 0 ????????????????????",
"??????????????????????? ???????????????????????",
"?????????????????????????? ??????????????????????????",
"?????????????????????????????? ??????????????????????????????"
}
Now I'd like each string in sys.map_table to be placed in a new table with each string having its own table of which the values are the characters in that string. Sounds confusing but this is what the new table should look like:
my_table = {
{"?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"," "," "," "," "," "," "," "," "," "," "," ","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"},
{"?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"," "," "," "," "," "," "," "," "," "," "," ","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?","?"},
}
Here is the function I am using to do such a thing:
function sys.scan_to_table()
sr = {}
local key = {
["?"] = "unknown",
["$"] = "black_hole",
["0"] = "planet_0",
["O"] = "planet_O",
["*"] = "star",
["N"] = "rocky_dead",
["M"] = "planet_M",
["B"] = "planet_B",
["A"] = "planet_A",
["D"] = "generic_dead",
[" "] = "space",
["H"] = "home",
["C"] = "planet_C",
["Q"] = "planet_Q",
}
for k,v in pairs( sys.map_table ) do
sr[k] = {}
str = v:reverse()
for count = 1, 71 do
for symbol, description in pairs( key ) do
if str:ends( symbol ) then
echo( count..": "..symbol.."\n")
sr[k][count] = symbol
str = str:cut( str:len() -1 )
end
end
end
end
end
The problem is that everytime there is a large group of spaces, the last space is not counted. So while each string of the map has 71 characters, my table is only grabbing 65-70 of them pending on how many groups of spaces are in the string.
If you create a global table named sys and paste in the two snippets of code I have here, you should be able to run sys.scan_to_table() without error. I've placed an echo in the function that shows what the count is along with the symbol its using. If you'll notice, after every group of space symbols, the count repeats itself.
Please please take the time to check this out and understand as I know it sounds complicated. But maybe one of you geniuses out there can see something I cannot.