The app I am currently developing is very data intensive, so I am trying to use nested tables and nested tables with key values to organize data. The issue I am having arises after I insert tables of data with key values into an existing table, and then try to update data assigned to key values in these inserted tables. I have duplicate key data that exists across multiple nested tables, so when I reassign one of the key values a new value, it updates all of the key values that exist across all of the nested tables, not just the one I am trying to update. Below is a code sample that illustrates the problem:
local table = { { "vacant", "vacant" }, { "vacant", "vacant" } } local nestedTable = { hello = "good-bye", something = "nothing", back = "forwards" } table[1][1] = nestedTable table[1][2] = nestedTable table[2][1] = nestedTable table[2][2] = nestedTable table[1][1].hello = "forever" table[1][2].hello = "eternity" print( table[1][1].hello ) print( table[1][2].hello ) print( table[2][1].hello ) print( table[2][2].hello )
The output from the code above should look like this:
forever
eternity
good-bye
good-bye
But, instead the output looks like this:
eternity
eternity
eternity
eternity
Any feedback as to what might be causing this problem or alternative ways to update key information without updating all the other keys in other nested tables would be appreciated! Thanks