Page 1 of 1
Persistant Data
Posted: Tue Aug 06, 2013 1:54 am
by zer0t3ch
Is there any way to store persistent data?
- I'm playing a game
- I save the game (I plan on using the game.onsave() event to know when to store the data)
- I close Factorio
- Open it back up later
- Load the save game
- The variable that I stored is still there for access
Re: Persistant Data
Posted: Tue Aug 06, 2013 10:26 am
by slpwnd
Anythin in the glob table is "automagically" saved and loaded for you. It works for plain data (integers, strings, tables, etc.) as well as for factorio objects (lua entity, lua technology, etc.). I would avoid storing functions in there.
Re: Persistant Data
Posted: Tue Aug 06, 2013 10:21 pm
by zer0t3ch
slpwnd wrote:Anythin in the glob table is "automagically" saved and loaded for you. It works for plain data (integers, strings, tables, etc.) as well as for factorio objects (lua entity, lua technology, etc.). I would avoid storing functions in there.
That's useful. I've been storing all my functions there!
Re: Persistant Data
Posted: Fri Aug 09, 2013 9:05 am
by slpwnd
zer0t3ch wrote:That's useful. I've been storing all my functions there!
In theory it should work for some simple functions. However it will fail for things like closures and generated functions. You can actually check the file called script.dat in the save directory. It contains the serialized state of the script. There are some binary data now and there but most of it should be readable and "lua-code" like.
Re: Persistant Data
Posted: Fri Aug 09, 2013 1:18 pm
by zer0t3ch
slpwnd wrote:zer0t3ch wrote:That's useful. I've been storing all my functions there!
In theory it should work for some simple functions. However it will fail for things like closures and generated functions. You can actually check the file called script.dat in the save directory. It contains the serialized state of the script. There are some binary data now and there but most of it should be readable and "lua-code" like.
Just looked at it. Doesn't look very friendly!
Re: Persistant Data
Posted: Fri Aug 09, 2013 2:53 pm
by drs9999
May I ask what advantages you expect when you store your functions in the glob table?
Re: Persistant Data
Posted: Sat Aug 10, 2013 6:17 pm
by zer0t3ch
drs9999 wrote:May I ask what advantages you expect when you store your functions in the glob table?
I had no clue what to expect, I just thought that was how you're supposed to do it...