This script does nothing by itself, but provides a simple API to handle configuration and data files. It is required for all of my modules.
Installation instructions: https://github.com/tes3mp-scripts/Tutorials
The following is a list of all functions in this module (and their arguments) you are expected to use in your scripts. If you required it in standard way, they will be accessible from the global DataManager
table.
loadConfiguration
scriptName
name by which you will be requesting your configuration file.defaultConfig
default values for your config file. Should be a complete and valid config, as it will simply be used if no file is found.keyOrder
array which defines order in which json keys should be written into the file, exposed from jsonInterface.save method
loadData
scriptName
same as for configurationdefaultData
value used for when the file isn't found.keyOrder
array which defines order in which json keys should be written into the file jsonInterface.save method
saveData
scriptName
data
data to write to the filekeyOrder
array which defines order in which json keys should be written into the file jsonInterface.save method
My branch of CoreScripts (likely to be merged for 0.8 release) provides configuration and data storage APIs out of the box.
If you want your script to function both in 0.7 and 0.8 (possible for most, maybe even all 0.7 scripts), you have two options:
- Use the new API (recommended)
- Your script will require
DataManager
for 0.7, but not for 0.8 - When running 0.7, data will only be saved on server exit, and not periodically
- Your script will require
- Keep using
DataManager
, which will use the new implementation automatically
Your script will requireDataManager
both for 0.7 and 0.8 There are a couple of nuances when running on 0.8:saveData
does nothing, data will be saved automatically instead- just like when using
storage
, if you want it data to be saved at all, you must alter the table you received fromloadData
, rather than create a new one when you change it
Example:
MyScript.data = DataManager.loadData("MyScript", {}) MyScript.data.players = {} -- ok, will be saved correctly MyScript.data = { players = {} } -- not ok, will not be saved MyScript.data = tableHelper.deepCopy(MyScript.data) -- not ok either
- for servers running Postgres, you must only
loadData
on or afterOnServerInit
event, e.g.:customEventHooks.registerHandler('OnServerInit', function(eventStatus) if not eventStatus.validDefaultHandler then return end MyScript.data = DataManager.loadData("MyScript", {}) end)
keyOrder
argument ofloadData
will be ignored for performance reasons