I have a table like this:
local tableofObjectTables = { } tableofObjectTables["a"] = "aObjects" tableofObjectTables["b"] = "bObjects" tableofObjectTables["c"] = "cObjects" tableofObjectTables["d"] = "dObjects"
aObject etc are all tables defined elsewhere. I want to copy the corresponding table depending on what letter a variable is. I’ve tried the following:
local selectedLetter = "a" local tabletoCopy1 = tableofObjectTables[selectedLetter] activeObjects = table.copy(tabletoCopy1)
I have also tried using “shallow copy” function in the lua documentation:
function shallowcopy(orig) local orig\_type = type(orig) local copy if orig\_type == 'table' then copy = {} for orig\_key, orig\_value in pairs(orig) do copy[orig\_key] = orig\_value end else -- number, string, boolean, etc copy = orig end return copy end
local selectedLetter = "a" shallowcopy(tableofObjectTables[selectedLetter])
In this case the string “aObject” is returned.
Thank you.