Saved custom data

grumblerbear

Chieftain
Joined
Sep 7, 2013
Messages
17
Hi, all, I have trouble and this causes severe pain. Sorry for my bad English.

I'm trying to make a mod that creates the need for food. Every turn units lost one food, but can accumulate it. The algorithm I wrote quickly, but the trouble with save data took a lot more time. I need to store data for each unit, available only to the save of which they are made.

I'm read:
http://modiki.civfanatics.com/index.php/Persisting_data_(Civ5)
http://forums.civfanatics.com/showthread.php?t=391102
and more, and more, and more...

I'm try:
SaveUtils.lua (Set/GetScriptData)
NewSaveUtils.lua (Modding.OpenSaveData)
Compilating with Set/Get PersistentData
and more, and more, and more...

I even tried to create a separate table with the DB.Query but fiasco

What I want?
Find out whether there is a sane method of storing data in a save file.
 
Tutorials and Utilities for saving data across save & reload of games.
  1. Pazyrk's Table Saver/Loader It is also advised to use [Mod Component] TSL Serializer | Add-on for TableSaverLoader because this cures issues related to multiple different mods all trying to use the TableSaver system at the same time.
  2. The Modwiki's Persisting Data (CIV5) page
  3. Whys' SaveUtils.lua thread page
  • There is also a "NewSaveUtils.lua" floating around the forum somewhere, but I don't have the link reference handy.
  • Plus there is one other Reference thread related to saving data across save/load of games but I am not sure how 'old' it is terms of methods commonly used now as opposed to when the game was originally released: robk's [REFERENCE] Storing data across saved games from LUA
 
I've already tried methods 2, 3, and referred to in the last paragraph. None of them meets the following requirements:
1. Accessing data from any lua file at any time. (SaveUtils have troubles with sync and caching)
2. The isolation of data between games. (PersistentData is global table, shared across games. I start new game and get data from old games. And caching data in this case is even greater problems with simultaneous access from different files)

Method 1 I try to study, however, would like to see specific suggestions - how exactly do you use the method? Whether or not you use what is on the links?
 
I trying to understand the source code of various modifications, but could not find one like in my case. The most that I've seen - storage of data within a single game session, mainly by SaveUtils or NewSaveUtils, but it does not fit me. If at the time of save at the unit has 6 units of food, then after loading should be 6 units. But if I create a new game, there are no data for the unit should not be.
 
I use #1. Always and Only, when I need to save data between save of game and reload of game by the user. See the code in Knights Templar World Wonder for a practical example of how to use the TableSaverLoader + TSLSerializerAddOn system. Even though I am only saving 3 pieces of data in an lua table for what turn, what city, what player built a particular wonder. I am not using the ability to save data across lua contexts, but you can do so by using MapModData which stores direct to the map and is therefore 'sharable' between contexts or even mods as I understand it. (I have never needed to use the MapModData so have no experience with it and cannot advise on any possible pitfalls).

I also use TableSaverLoader in my Civ-Linked Great Generals mod, and there I save nearly 2000 pieces of information in several different tables.

TableSaverLoader saves your data when the user presses "Save Game" or uses the hotkey for saving a game, or uses the "Quick Save" button, so does not cause data desynch: the data it retrieves on reload of a saved game is the data that was directly saved into that saved game file.
 
It work (data load/save), but I also need to transfer data between files.

I have UnitPanel.lua for display data, supply.lua for data changes and MyUtils.lua with functions (set/get supply and tableload includes). I have global var gSupply in MyUtils.lua, but UnitPanel.lua get wrong data... global var is not work for my case :(

Shall I forced to use cumbersome SaveUtils for data transfer within the same mod?
 
http://forums.civfanatics.com/showthread.php?t=442249

See in the 1st post the section on "Sharing between mods":
Sharing between mods

Don't have two different mods (or two different states) including TableSaverLoader and saving/loading the same table. This will break since each mod (or state) is keeping its own Lua representation of what is in that DB table, and when one updates, inserts or deletes the other won't know it. You can have each save/loading their own global persisted table as explained above. Or... you can have one mod running TableSaverLoader and then share the "global persisted table" among mods. It's easy to create a table and pass it among all mods so that they share it. Just take advantage of MapModData table which is already shared and named in all Lua states:
Code:
MapModData.gT = MapModData.gT or {}
gT = MapModData.gT
Load order doesn't matter with this code. Whichever mod happens to load first will create a table. All subsequently loaded mods will use the already created table and name it "gT" within their respective environment. You can use the same exact code to share a table among states within a mod, for example to pass data between your mod state and UI states.
Note the portion I highlighted Bold and Blue. But I have never needed to use this functionality so don't know if there non-obvious pitfalls with regard to using this method for sharing data between contexts within your mod.
 
Back
Top Bottom