• We are currently performing site maintenance, parts of civfanatics are currently offline, but will come back online in the coming days. For more updates please see here.

[LUA] Persistent Data

AW Arcaeca

Deus Vult
Joined
Mar 10, 2013
Messages
3,019
Location
Operation Padlock ground zero
Basically, I'd like a way to store variables between saves. For Booleans it can easily be done by giving a city a dummy building and then detecting whether or not the dummy build is present, but optimally I'd like to use as few dummy buildings as possible. That's where persistent data handling comes in.

The problem is... I don't know how to do it. The wiki has some information on it (thanks to Machiavelli24 for the link), but like almost everything on the wiki it's almost entirely unclear and conveys very little understandable or useful information. So I was wondering - does anyone know of a good lua tutorial for persisting save data for modding, either on the forums or just anywhere? Or can anyone just tell me how to do it?

TIA,
AW
 
Or can anyone just tell me how to do it?

TIA,
AW

I believe there's an existing set of Lua commands called SaveUtils.lua floating around, that I've used in the past to retain information. (I used it in my Human Village mod to keep track of buildings built in my cities.) There's a newer version whose name escapes me at the moment, as well -- I know DarkScythe was using it for one mod he's working on. Hopefully someone will be by to provide more details on it. Hopefully either file may be able to give you the functionality you're looking for.
 
Using NewSaveUtils.lua, you can store values across saves:

https://www.dropbox.com/s/ghmlhx9iw52ohjp/NewSaveUtils.lua

Include the lua file in your main code with Include("NewSaveUtils.lua"), importing it to VFS, and use SetPersistantProperty("Key", value) to store a variable, where key is the variable name and value is the value, and GetPersistantProperty("Key") to retrive that information.

More info:
http://forums.civfanatics.com/showthread.php?t=392958&page=11
That actually sounds a lot easier than I expected. Thanks JFD! :thumbsup: I'll try it out.
 
I believe there's an existing set of Lua commands called SaveUtils.lua floating around, that I've used in the past to retain information. (I used it in my Human Village mod to keep track of buildings built in my cities.) There's a newer version whose name escapes me at the moment, as well -- I know DarkScythe was using it for one mod he's working on. Hopefully someone will be by to provide more details on it. Hopefully either file may be able to give you the functionality you're looking for.

I use Pazyryk's TableSaverLoader Lua script for my mod's needs.

I think for fairly simple single-item, on-demand storage, SaveUtils (and I suppose NewSaveUtils, by extension) are the easiest ones to use for that purpose, as it seems very similar in usage to SetScriptData() and GetScriptData().

I believe TableSaverLoader stores its data periodically into one of the Game's databases as well.

However, for my needs, I enjoy TableSaveLoader's increased functionality, as it allows me to store multiple properties about specific things, and I can loop through it like I would a normal table in order to find things.
 
Back
Top Bottom