Can I Combine My 6 Lua Tables Into One Super Table?

My current project uses 6 different lua tables to manage its data.  I save and load the tables from 6 separate json files.

Is there a way in which to structure a lua table so that all the data resides in this single table, thus a single json file?

my tables are currently

gameTable  1 dimensional table with 10 values

empireTable 2 dim table with 2-4 players with 14 values assigned for each player. 

leaderTable 2 dim table with up to 20 leaders with 12 values each

three map files

mapControl 1 dim array with 8 values

mapTable    3 dim table representing a 10 by 10 grid, with 5 values for each square in the grid

mapTable2  if the map is double layer then this is the same set up as above

I have no idea how to structure it into a single table or if it’s possible

let me know your thoughts?

I’ve done it before with lua tables.

My example is here : https://github.com/CraftyDeano/Localization-Template/blob/master/translations.lua

I have a main translation table, and inside that a table for each word/phrase I want to translate.

Check out the main.lua in the project folder to see how to pull the data. Its just mainTable[subTable][foo]

if I had the following tables

gameTable  

empireTable

leaderTable 

mapControl

mapTable   

mapTable2 

 

 

i can make a new table

----------------------------------------------------------code

saveAll = {

      gameTable  = gameTable,

      empireTable = empireTable,

      leaderTable  =  leaderTable,

      mapControl  = mapControl,

      mapTable   = mapTable,

      mapTable2 = mapTable2,

}

----------------------------------------------------------end code

then I can simply…

----------------------------------------------------------code

local dataToSave = json.encode(saveAll)

----------------------------------------------------------end code

and save that to a file

    

For me, I just did a search and replace for my relevant tables and added game. as “prefix,” then added local game = {} at the top of my code.

From there, I was able to do a local result = saveTable( game, “gamedata.txt” ) to save the entire super table.

I’ve done it before with lua tables.

My example is here : https://github.com/CraftyDeano/Localization-Template/blob/master/translations.lua

I have a main translation table, and inside that a table for each word/phrase I want to translate.

Check out the main.lua in the project folder to see how to pull the data. Its just mainTable[subTable][foo]

if I had the following tables

gameTable  

empireTable

leaderTable 

mapControl

mapTable   

mapTable2 

 

 

i can make a new table

----------------------------------------------------------code

saveAll = {

      gameTable  = gameTable,

      empireTable = empireTable,

      leaderTable  =  leaderTable,

      mapControl  = mapControl,

      mapTable   = mapTable,

      mapTable2 = mapTable2,

}

----------------------------------------------------------end code

then I can simply…

----------------------------------------------------------code

local dataToSave = json.encode(saveAll)

----------------------------------------------------------end code

and save that to a file

    

For me, I just did a search and replace for my relevant tables and added game. as “prefix,” then added local game = {} at the top of my code.

From there, I was able to do a local result = saveTable( game, “gamedata.txt” ) to save the entire super table.