I'm a hobby programmer who's never worked in LUA before (VBA/VB.NET/C#) and I'm working on a mod but I'm not sure how arrays/data tables are handled in LUA and how they should be.
I'll be storing some basic information.
Name,
X1, X2, Y1, Y2 (Area co-ords)
amount, (Integer)
CentreX, CentreY (Calculated from Area co-ords)
It should be a add only, no need to remove entries.
The data will be persistent per save.
How should I store this? What tips/tricks should I get to know?
So far I have everything I need, except how to store that. And debugging as I don't think we can step through the code live.
Data Tables for n00bs and how to handle them
-
- Filter Inserter
- Posts: 256
- Joined: Wed May 13, 2015 5:28 am
- Contact:
-
- Filter Inserter
- Posts: 778
- Joined: Sun Sep 07, 2014 12:59 pm
- Contact:
Re: Data Tables for n00bs and how to handle them
You'll probably find http://www.lua.org/pil/11.html useful.
To make things include in the save, use global. (for example
As for debugging: I tend to use some strategically placed game.player.print() statements. If it's a structure that needs dumping, serpent.dump() is useful.
To make things include in the save, use global. (for example
Code: Select all
table.insert(global.yourmod, yourstruct)
I don't have OCD, I have CDO. It's the same, but with the letters in the correct order.
-
- Filter Inserter
- Posts: 256
- Joined: Wed May 13, 2015 5:28 am
- Contact:
Re: Data Tables for n00bs and how to handle them
Thanks for the reply 
I'll definitely have a look through that site. Most of what I've found has been rather specific examples on stackoverflow.com
I haven't seen any reference to Serpent.dump before. Any idea where I could find some information on it?

I'll definitely have a look through that site. Most of what I've found has been rather specific examples on stackoverflow.com
I haven't seen any reference to Serpent.dump before. Any idea where I could find some information on it?
-
- Filter Inserter
- Posts: 778
- Joined: Sun Sep 07, 2014 12:59 pm
- Contact:
Re: Data Tables for n00bs and how to handle them
I've seen it mentioned across the forums a few times. Google returned https://github.com/pkulchenko/serpent, which may have some useful information (not quite sure if Factorio implements the most recent version though, so that page may differ from Factorio)
I don't have OCD, I have CDO. It's the same, but with the letters in the correct order.