Page 1 of 1

Data Tables for n00bs and how to handle them

Posted: Mon Sep 28, 2015 8:05 am
by PiggyWhiskey
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.

Re: Data Tables for n00bs and how to handle them

Posted: Tue Sep 29, 2015 8:56 am
by Boogieman14
You'll probably find http://www.lua.org/pil/11.html useful.

To make things include in the save, use global. (for example

Code: Select all

table.insert(global.yourmod, yourstruct)
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.

Re: Data Tables for n00bs and how to handle them

Posted: Tue Sep 29, 2015 9:01 am
by PiggyWhiskey
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?

Re: Data Tables for n00bs and how to handle them

Posted: Tue Sep 29, 2015 9:10 am
by Boogieman14
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)