Explanation and Walkthrough
You can do this; make a table called whatever youâd like. In this case, weâll name it âconversions.â Next, fill in the table with tables inside of it, with those ânested tablesâ being formed of two elements. First the number, and second the letter(s) you want that number to be referenced to. Following the picture you showed in your post, it should look like this:
local conversions = {
{1, "A"},
{2, "B"},
{3, "C"},
{27, "AA"},
{28, "AB"},
{29, "AC"},
{52, "BA"},
{53, "BB"},
{54, "BC"}
}
Then make a function that will take input as the number you want to convert, linearly search through the table for that number, and return the according letter it finds in the table. Like this:
local function returnLetter(numInput)
for i = 1, #conversions, 1 do
if conversions[i][1] == numInput then
return conversions[i][2]
end
end
end
Then to use this function, all you need to do is set a variable to the function itself, with the parameter being the number youâd like to have converted. Then in this case, weâll simple print the return value:
local ret = returnLetter(2)
print(ret)
The Final Result
local conversions = {
{1, "A"},
{2, "B"},
{3, "C"},
{27, "AA"},
{28, "AB"},
{29, "AC"},
{52, "BA"},
{53, "BB"},
{54, "BC"}
}
local function returnLetter(numInput)
for i = 1, #conversions, 1 do
if conversions[i][1] == numInput then
return conversions[i][2]
end
end
end
local ret = returnLetter(2)
print(ret)
Hopefully this helped! Have a good week.
Extra Note: Donât worry about changing the values in the table. As long as you follow the same format - the tables with the numbers first and letters second - and make sure to place commas between those tables that are within the main conversions
table, everything should work fine and self adjust.