Persistant Data

Place to get help with not working mods / modding interface.
User avatar
zer0t3ch
Fast Inserter
Fast Inserter
Posts: 118
Joined: Fri Jul 26, 2013 6:06 am
Contact:

Persistant Data

Post 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
"F**k thy hater"
-George Watsky

Feel free to contact me!
Skype: Zer0t3ch
Razer Comms: Zer0t3ch
Email: zer0t3ch@live.com

Image
slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: Persistant Data

Post 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.
User avatar
zer0t3ch
Fast Inserter
Fast Inserter
Posts: 118
Joined: Fri Jul 26, 2013 6:06 am
Contact:

Re: Persistant Data

Post 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! :roll:
"F**k thy hater"
-George Watsky

Feel free to contact me!
Skype: Zer0t3ch
Razer Comms: Zer0t3ch
Email: zer0t3ch@live.com

Image
slpwnd
Factorio Staff
Factorio Staff
Posts: 1835
Joined: Sun Feb 03, 2013 2:51 pm
Contact:

Re: Persistant Data

Post 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.
User avatar
zer0t3ch
Fast Inserter
Fast Inserter
Posts: 118
Joined: Fri Jul 26, 2013 6:06 am
Contact:

Re: Persistant Data

Post 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! :P
"F**k thy hater"
-George Watsky

Feel free to contact me!
Skype: Zer0t3ch
Razer Comms: Zer0t3ch
Email: zer0t3ch@live.com

Image
drs9999
Filter Inserter
Filter Inserter
Posts: 831
Joined: Wed Mar 06, 2013 11:16 pm
Contact:

Re: Persistant Data

Post by drs9999 »

May I ask what advantages you expect when you store your functions in the glob table?
User avatar
zer0t3ch
Fast Inserter
Fast Inserter
Posts: 118
Joined: Fri Jul 26, 2013 6:06 am
Contact:

Re: Persistant Data

Post 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...
"F**k thy hater"
-George Watsky

Feel free to contact me!
Skype: Zer0t3ch
Razer Comms: Zer0t3ch
Email: zer0t3ch@live.com

Image
Post Reply

Return to “Modding help”