Help with using tables

Hi there.

If you change your table keys (the left of each value assignment) to be the exact string which you would receive from text, you can easily do this.
Like so:

local lettertable = {
	["0"] = "0,0",
	["1"] = "8,0",
	["2"] = "16,0",
	["3"] "24,0",
	["4"] = "32,0",
	["5"] = "40,0",
	["6"] = "48,0",
	["7"] = "56,0",
	["8"] = "64,0",
	["9"] = "72,0",
	A = "0,8",
	B = "0,16",
	C = "0,24", 
}

It’s crucial that the numbers are wrapped in [""] as otherwise you will get a syntax error. The rest can be written like normal.

Then simply index the table, like so:

local text = "ABC123"
for index = 1, #text, 1 do
	local character = text:sub(index, index)
	print(lettertable[character])
end


Also for custom font rendering I have to recommend my awesome, open-source module; Text+.
It’s super efficient, easy, and powerful.

3 Likes