Messy Tables: Better way?

Alright, I’m reading data from a text file and converting to tables and data. It’s becoming too complicated and need help simplifying. I’ve been using string.Explode() thus far and it’s getting a bit too confusing.

Here’s an example text file:


Here’s how this is formatted:
[li]The “;” separates the Main from the data.
[/li][li]The “=” separates the Title from the number data.
[/li][li]The “,” separates the Titles/Number data from one another.
[/li][li]The “-” separates the Mains from one another.
Here’s how I want it to turn out:
mytable[“Stuff”][“Main”].Data[“Title”] = “123”
mytable[“Stuff”][“Main”].Data[“Title2”] = “345”

mytable[“Stuff”][“Main2”].Data[“LOL”] = “012”
mytable[“Stuff”][“Main2”].Data[“LOL2”] = “333”

mytable[“Stuff”][“Main3”].Data[“whatever”] = “01”
mytable[“Stuff”][“Main3”].Data[“whatever2”] = “93”
You get the idea.

The thing is that I want to be able to access the “Main”, “Title”, and Number data when it’s all said and done with. I don’t even want to show my code because it’s an utter mess at this point. I either need someone to show me how to do this right, or show me a better way of doing it all together.

Try this:

Text file:



for k , v in pairs(string.Explode("
" , file.Read("Myfile.txt")) do
	sExp = string.Explode("|" , v)
	MyTable[sExp[1]].sExp[2][sExp[3]] = sExp[4]

I’m not too sure if that is what you want, but it should work.

Sorta, but the problem is that “Title” needs to correspond to “123”, and “Title2” needs to correspond to “345”.


The thing is that there could be a Title3 and a 678 number after that. It needs to be flexible.

for k , v in pairs(string.Explode("
" , file.Read("Myfile.txt")) do
	sExp = string.Explode("|" , v)
	MyTable[sExp[1]].sExp[2] = sExp[3]
	MyTable[sExp[1]].sExp[4] = sExp[5]

local newtable = glon.decode(file.Read("data.txt"))

What’s wrong with that?

You don’t get it. I plan to change the text files regularly, and need it to be flexible enough so I don’t need to change all the numbers in the code. For example, if I added a Title4 and Title5 along with their numbers, I’d need to write 4 more lines of code. I need this to be modular. The code should not have to depend on the text.


Because I’m not creating the text file values in lua. Besides that’s not the problem.