in Lua, I have a large number of tables named A-Z (I referenced just 2 below). I have a function NextVar(PreviousVar) which I use to cycle the output from A-Z. but when I try to print a value from a table (A[1] for example), it prints nil instead. How can I transform the return value from the function into a usable variable?
A = {10, 33, 35}
B = {15, 55, 45}
local alphabet = "1ABCDEFGHIJKLMNOPQRSTUVWXYZ"
function NextVar(PreviousVar)
local index = string.find(alphabet, PreviousVar)
if index then
index = (index % #alphabet) + 1 -- move to next letter, wrapping at end
return alphabet:sub(index, index)
end
end
PreviousVar = "1"
repeat
if NextVar(PreviousVar) != nil then
x = NextVar(PreviousVar)
print(x) -- works as it prints A,B,C,D, etc
print(x[1]) -- just prints nil
PreviousVar = NextVar(PreviousVar)
end
until PreviousVar == nil```