mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
2872 lines
98 KiB
HTML
2872 lines
98 KiB
HTML
|
|
|
|
<!doctype html>
|
|
<html class="no-js" lang="">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<title>Datastore core</title>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
<link rel="stylesheet" href="../spectre.min.css" type="text/css" />
|
|
<link rel="stylesheet" href="../spectre-icons.min.css" type="text/css" />
|
|
<link rel="stylesheet" href="../ldoc.css" type="text/css" />
|
|
</head>
|
|
<body>
|
|
|
|
<div class="container grid-1280">
|
|
<div class="columns">
|
|
|
|
<!-- sidebar start -->
|
|
|
|
<div id="sidebar" class="column col-3 col-sm-12">
|
|
|
|
<div class="sidebar-custom">
|
|
|
|
<div class="project-infobox">
|
|
|
|
<!-- project title -->
|
|
|
|
<a href="../index.html"><h1>ExpGaming Scenario</h1></a>
|
|
|
|
<!-- project description -->
|
|
<p class="project-desc">Explosive Gaming's server scenario for 0.18</p>
|
|
|
|
<!-- project full description -->
|
|
</div>
|
|
|
|
|
|
<!-- sidebar navigation -->
|
|
<!-- list of items in a module -->
|
|
<ul class="nav nav-module-contents">
|
|
<li class="nav-item">
|
|
<h2>Sections</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><a href="#Dependencies"><span class="fragment-hashtag">#</span> Dependencies</a></li>
|
|
<li class="nav-item"><a href="#Fields"><span class="fragment-hashtag">#</span> Fields</a></li>
|
|
<li class="nav-item"><a href="#Datastore_Manager"><span class="fragment-hashtag">#</span> Datastore Manager </a></li>
|
|
<li class="nav-item"><a href="#Datastore_Internal"><span class="fragment-hashtag">#</span> Datastore Internal </a></li>
|
|
<li class="nav-item"><a href="#Datastore_Local"><span class="fragment-hashtag">#</span> Datastore Local </a></li>
|
|
<li class="nav-item"><a href="#Datastore_External"><span class="fragment-hashtag">#</span> Datastore External </a></li>
|
|
<li class="nav-item"><a href="#Events"><span class="fragment-hashtag">#</span> Events </a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Core</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Async.html"><span class="module-name-item">Async</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Commands.html"><span class="module-name-item">Commands</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Common.html"><span class="module-name-item">Common</span></a></div></li>
|
|
<li class="nav-item active"><div class="nav-item-block-active block"><a href="../core/Datastore.html"><span class="module-name-item">Datastore</span></a><i class="icon icon-arrow-left icon-arrow-left-custom"></i></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Gui.html"><span class="module-name-item">Gui</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Groups.html"><span class="module-name-item">Groups</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/PlayerData.html"><span class="module-name-item">PlayerData</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Roles.html"><span class="module-name-item">Roles</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../core/Store.html"><span class="module-name-item">Store</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Control</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Jail.html"><span class="module-name-item">Jail</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Production.html"><span class="module-name-item">Production</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Reports.html"><span class="module-name-item">Reports</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Rockets.html"><span class="module-name-item">Rockets</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Tasks.html"><span class="module-name-item">Tasks</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Warnings.html"><span class="module-name-item">Warnings</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../control/Warps.html"><span class="module-name-item">Warps</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Addons</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Advanced-Start.html"><span class="module-name-item">Advanced-Start</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Chat-Popups.html"><span class="module-name-item">Chat-Popups</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Chat-Reply.html"><span class="module-name-item">Chat-Reply</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Compilatron.html"><span class="module-name-item">Compilatron</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Damage-Popups.html"><span class="module-name-item">Damage-Popups</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Death-Logger.html"><span class="module-name-item">Death-Logger</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Discord-Alerts.html"><span class="module-name-item">Discord-Alerts</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/greetings.html"><span class="module-name-item">greetings</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Inventory-Clear.html"><span class="module-name-item">Inventory-Clear</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Pollution-Grading.html"><span class="module-name-item">Pollution-Grading</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Player-Colours.html"><span class="module-name-item">Player-Colours</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Scorched-Earth.html"><span class="module-name-item">Scorched-Earth</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Spawn-Area.html"><span class="module-name-item">Spawn-Area</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../addons/Tree-Decon.html"><span class="module-name-item">Tree-Decon</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Guis</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Player-List.html"><span class="module-name-item">Player-List</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Readme.html"><span class="module-name-item">Readme</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Rocket-Info.html"><span class="module-name-item">Rocket-Info</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Science-Info.html"><span class="module-name-item">Science-Info</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/server-ups.html"><span class="module-name-item">server-ups</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Task-List.html"><span class="module-name-item">Task-List</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../guis/Warps-List.html"><span class="module-name-item">Warps-List</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Commands</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Admin-Chat.html"><span class="module-name-item">Admin-Chat</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Bonus.html"><span class="module-name-item">Bonus</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Cheat-Mode.html"><span class="module-name-item">Cheat-Mode</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Clear-Inventory.html"><span class="module-name-item">Clear-Inventory</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Debug.html"><span class="module-name-item">Debug</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Find.html"><span class="module-name-item">Find</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Help.html"><span class="module-name-item">Help</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Home.html"><span class="module-name-item">Home</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Interface.html"><span class="module-name-item">Interface</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Jail.html"><span class="module-name-item">Jail</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Kill.html"><span class="module-name-item">Kill</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Me.html"><span class="module-name-item">Me</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Quickbar.html"><span class="module-name-item">Quickbar</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Rainbow.html"><span class="module-name-item">Rainbow</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Repair.html"><span class="module-name-item">Repair</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Reports.html"><span class="module-name-item">Reports</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Roles.html"><span class="module-name-item">Roles</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Spawn.html"><span class="module-name-item">Spawn</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Tag.html"><span class="module-name-item">Tag</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Teleport.html"><span class="module-name-item">Teleport</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../commands/Warnings.html"><span class="module-name-item">Warnings</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Configs</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/File-Loader.html"><span class="module-name-item">File-Loader</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Advanced-Start.html"><span class="module-name-item">Advanced-Start</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Bonuses.html"><span class="module-name-item">Bonuses</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Chat-Reply.html"><span class="module-name-item">Chat-Reply</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Compilatron.html"><span class="module-name-item">Compilatron</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Death-Logger.html"><span class="module-name-item">Death-Logger</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Discord-Alerts.html"><span class="module-name-item">Discord-Alerts</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Auth-Admin.html"><span class="module-name-item">Commands-Auth-Admin</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Auth-Roles.html"><span class="module-name-item">Commands-Auth-Roles</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Parse.html"><span class="module-name-item">Commands-Parse</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Parse-Roles.html"><span class="module-name-item">Commands-Parse-Roles</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Commands-Auth-Runtime-Disable.html"><span class="module-name-item">Commands-Auth-Runtime-Disable</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Permission-Groups.html"><span class="module-name-item">Permission-Groups</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Roles.html"><span class="module-name-item">Roles</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Player-List.html"><span class="module-name-item">Player-List</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Rockets.html"><span class="module-name-item">Rockets</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Science.html"><span class="module-name-item">Science</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Tasks.html"><span class="module-name-item">Tasks</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Warps.html"><span class="module-name-item">Warps</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/inventory_clear.html"><span class="module-name-item">inventory_clear</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Pollution-Grading.html"><span class="module-name-item">Pollution-Grading</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Popup-Messages.html"><span class="module-name-item">Popup-Messages</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Preset-Player-Colours.html"><span class="module-name-item">Preset-Player-Colours</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Preset-Player-Quickbar.html"><span class="module-name-item">Preset-Player-Quickbar</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Repair.html"><span class="module-name-item">Repair</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Scorched-Earth.html"><span class="module-name-item">Scorched-Earth</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Spawn-Area.html"><span class="module-name-item">Spawn-Area</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../configs/Warnings.html"><span class="module-name-item">Warnings</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Modules</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/control.html"><span class="module-name-item">control</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/modules.addons.station-auto-name.html"><span class="module-name-item">modules.addons.station-auto-name</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/overrides.debug.html"><span class="module-name-item">overrides.debug</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/overrides.math.html"><span class="module-name-item">overrides.math</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/overrides.table.html"><span class="module-name-item">overrides.table</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.event.html"><span class="module-name-item">utils.event</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.event_core.html"><span class="module-name-item">utils.event_core</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../modules/utils.task.html"><span class="module-name-item">utils.task</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<ul class="nav nav-modules">
|
|
<li class="nav-item">
|
|
<h2>Topics</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../topics/README.md.html"><span class="module-name-item">README.md</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../topics/LICENSE.html"><span class="module-name-item">LICENSE</span></a></div></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
</div>
|
|
<div class="up-to-top">
|
|
<!-- list of items in a module -->
|
|
<ul class="nav nav-module-contents">
|
|
<li class="nav-item">
|
|
<h4>Jump to Section</h4>
|
|
<ul class="nav">
|
|
<li class="nav-item"><a href="#Dependencies"><span class="fragment-hashtag">#</span> Dependencies</a></li>
|
|
<li class="nav-item"><a href="#Fields"><span class="fragment-hashtag">#</span> Fields</a></li>
|
|
<li class="nav-item"><a href="#Datastore_Manager"><span class="fragment-hashtag">#</span> Datastore Manager </a></li>
|
|
<li class="nav-item"><a href="#Datastore_Internal"><span class="fragment-hashtag">#</span> Datastore Internal </a></li>
|
|
<li class="nav-item"><a href="#Datastore_Local"><span class="fragment-hashtag">#</span> Datastore Local </a></li>
|
|
<li class="nav-item"><a href="#Datastore_External"><span class="fragment-hashtag">#</span> Datastore External </a></li>
|
|
<li class="nav-item"><a href="#Events"><span class="fragment-hashtag">#</span> Events </a></li>
|
|
</ul>
|
|
</li>
|
|
</ul>
|
|
<a href="#">Top <i class="icon icon-upward"></i></a>
|
|
</div>
|
|
</div>
|
|
<!-- sidebar end -->
|
|
|
|
<!-- content body start -->
|
|
<div class="column col-9 col-sm-12">
|
|
|
|
<!-- module list on the main page start -->
|
|
<!-- module list on the main page end -->
|
|
|
|
<!-- module contents -->
|
|
|
|
<!-- module content header start -->
|
|
|
|
<h2><span class="body-module-name"><strong><em>Datastore</em></strong></span> core</h2>
|
|
<p>Core Module - Datastore
|
|
- A module used to store data in the global table with the option to have it sync to an external source.</p>
|
|
<p></p>
|
|
|
|
|
|
<!-- module info start -->
|
|
<!-- module info end -->
|
|
|
|
<!-- module usage start -->
|
|
<h3>Usage</h3>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Types of Datastore
|
|
</span><span class="comment">-- This datastore will not save data externally and can be used to watch for updates on values within it
|
|
</span><span class="comment">-- A common use might be to store data for a gui and only update the gui when a value changes
|
|
</span><span class="keyword">local</span> LocalDatastore = Datastore.connect(<span class="string">'LocalDatastore'</span>)
|
|
|
|
<span class="comment">-- This datastore will allow you to use the save and request method, this allows you to have persistent data
|
|
</span><span class="comment">-- Should be used over auto save as it creates less save requests, but this means you need to tell the data to be saved
|
|
</span><span class="comment">-- We use this type for player data as we know the data only needs to be saved when the player leaves
|
|
</span><span class="keyword">local</span> PersistentDatastore = Datastore.connect(<span class="string">'PersistentDatastore'</span>, <span class="keyword">true</span>) <span class="comment">-- save_to_disk
|
|
</span>
|
|
<span class="comment">-- This datastore is the same as above but the save method will be called automatically when ever you change a value
|
|
</span><span class="comment">-- An auto save datastore should be used if the data does not change often, this can be global settings and things of that sort
|
|
</span><span class="comment">-- If it is at all possible to setup events to unload and/or save the data then this is preferable
|
|
</span><span class="keyword">local</span> AutosaveDatastore = Datastore.connect(<span class="string">'AutosaveDatastore'</span>, <span class="keyword">true</span>, <span class="keyword">true</span>) <span class="comment">-- save_to_disk, auto_save
|
|
</span>
|
|
<span class="comment">-- Finally you can have a datastore that propagates its changes to all other connected servers, this means request does not need to be used
|
|
</span><span class="comment">-- This should be used when you might have data conflicts while saving, this is done by pushing the saved value to all active servers
|
|
</span><span class="comment">-- The request method has little use after server start as any external changes to the value will be pushed automatically
|
|
</span><span class="comment">-- Auto save can also be used with this type and you should follow the same guidelines above for when this should be avoided
|
|
</span><span class="keyword">local</span> PropagateDatastore = Datastore.connect(<span class="string">'PropagateDatastore'</span>, <span class="keyword">true</span>, <span class="keyword">false</span>, <span class="keyword">true</span>) <span class="comment">-- save_to_disk, propagate_changes
|
|
</span></code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Using Datastores Locally
|
|
</span><span class="comment">-- Once you have your datastore connection setup, any further requests with connect will return the same datastore
|
|
</span><span class="comment">-- This is important to know because the settings passed as parameters you have an effect when it is first created
|
|
</span>
|
|
<span class="comment">-- One useful thing that you might want to set up before runtime is a serializer, this will convert non string keys into strings
|
|
</span><span class="comment">-- This serializer will allow use to pass a player object and still have it serialized to the players name
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:set_serializer(<span class="keyword">function</span>(rawKey)
|
|
<span class="keyword">return</span> rawKey.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- If we want to get data from the datastore we can use get or get_all
|
|
</span><span class="keyword">local</span> value = ExampleData:get(player, defaultValue)
|
|
<span class="keyword">local</span> values = ExampleData:get_all()
|
|
|
|
<span class="comment">-- If we want to set data then we can use set, increment, update, or update_all
|
|
</span>ExampleData:set(player, <span class="number">10</span>)
|
|
ExampleData:increment(player)
|
|
ExampleData:update(player, <span class="keyword">function</span>(player_name, value)
|
|
<span class="keyword">return</span> value * <span class="number">2</span>
|
|
<span class="keyword">end</span>)
|
|
ExampleData:update_all(<span class="keyword">function</span>(player_name, value)
|
|
<span class="keyword">return</span> value * <span class="number">2</span>
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- If we want to remove data then we use remove
|
|
</span>ExampleData:remove(player)
|
|
|
|
<span class="comment">-- We can also listen for updates to a value done by any of the above methods with on_update
|
|
</span>ExampleData:on_update(<span class="keyword">function</span>(player_name, value)
|
|
game.<span class="global">print</span>(player_name..<span class="string">' has had their example data updated to '</span>..<span class="global">tostring</span>(value))
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Using Datastore Externally
|
|
</span><span class="comment">-- If save_to_disk is used then this opens up the option for persistent data which you can request, save, and remove
|
|
</span><span class="comment">-- All of the local methods are still usable put now there is the option for extra events
|
|
</span><span class="comment">-- In order for this to work there must be an external script to read datastore.pipe and inject with Datastore.ingest
|
|
</span>
|
|
<span class="comment">-- To request data you would use request and the on_load event, this event can be used to modify data before it is used
|
|
</span>ExampleData:request(player)
|
|
ExampleData:on_load(<span class="keyword">function</span>(player_name, value)
|
|
game.<span class="global">print</span>(<span class="string">'Loaded example data for '</span>..player_name)
|
|
<span class="comment">-- A value can be returned here to overwrite the received value
|
|
</span><span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- To save data you would use save and the on_save event, this event can be used to modify data before it is saved
|
|
</span>ExampleData:save(player)
|
|
ExampleData:on_save(<span class="keyword">function</span>(player_name, value)
|
|
game.<span class="global">print</span>(<span class="string">'Saved example data for '</span>..player_name)
|
|
<span class="comment">-- A value can be returned here to overwrite the value which is saved
|
|
</span><span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- To remove data locally but not externally, like if a player logs off, you would use unload and on_unload
|
|
</span>ExampleData:unload(player)
|
|
ExampleData:on_unload(<span class="keyword">function</span>(player_name, value)
|
|
game.<span class="global">print</span>(<span class="string">'Unloaded example data for '</span>..player_name)
|
|
<span class="comment">-- Any return is ignored, this is event is for cleaning up other data
|
|
</span><span class="keyword">end</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Using Datastore Messaging
|
|
</span><span class="comment">-- The message action can be used regardless of save_to_disk being set as no data is saved, but an external script is still required
|
|
</span><span class="comment">-- These messages can be used to send data to other servers which doesnt need to be saved such as shouts or commands
|
|
</span><span class="comment">-- Using messages is quite simple only using message and on_message
|
|
</span>ExampleData:message(key, message)
|
|
ExampleData:on_message(<span class="keyword">function</span>(key, message)
|
|
game.<span class="global">print</span>(<span class="string">'Received message '</span>..message)
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Combined Datastores
|
|
</span><span class="comment">-- A combined datastore is a datastore which stores its data inside of another datastore
|
|
</span><span class="comment">-- This means that the data is stored more efficiently in the external database and less requests need to be made
|
|
</span><span class="comment">-- To understand how combined datastores work think of each key in the parent as a table where the sub datastore is a key in that table
|
|
</span><span class="comment">-- Player data is the most used version of the combined datastore, below is how the player data module is setup
|
|
</span><span class="keyword">local</span> PlayerData = Datastore.connect(<span class="string">'PlayerData'</span>, <span class="keyword">true</span>) <span class="comment">-- saveToDisk
|
|
</span>PlayerData:set_serializer(Datastore.name_serializer) <span class="comment">-- use player name as key
|
|
</span>PlayerData:combine(<span class="string">'Statistics'</span>)
|
|
PlayerData:combine(<span class="string">'Settings'</span>)
|
|
PlayerData:combine(<span class="string">'Required'</span>)
|
|
|
|
<span class="comment">-- You can then further combine datastores to any depth, below we add some possible settings and statistics that we might use
|
|
</span><span class="comment">-- Although we dont in this example, each of these functions returns the datastore object which you should use as a local value
|
|
</span>PlayerData.Settings:combine(<span class="string">'Color'</span>)
|
|
PlayerData.Settings:combine(<span class="string">'Quickbar'</span>)
|
|
PlayerData.Settings:combine(<span class="string">'JoinMessage'</span>)
|
|
PlayerData.Statistics:combine(<span class="string">'Playtime'</span>)
|
|
PlayerData.Statistics:combine(<span class="string">'JoinCount'</span>)
|
|
|
|
<span class="comment">-- Because sub datastore work just like a normal datastore you dont need any special code, using get and set will still return as if it wasnt a sub datastore
|
|
</span><span class="comment">-- Things like the serializer and the datastore settings are always the same as the parent so you dont need to worry about setting up the serializer each time
|
|
</span><span class="comment">-- And because save, request, and unload methods all point to the root datastore you are able to request and save your data as normal
|
|
</span>
|
|
<span class="comment">-- If you used get_all on PlayerData this is what you would get:
|
|
</span>{
|
|
Cooldude2606 = {
|
|
Settings = {
|
|
Color = <span class="string">'ColorValue'</span>,
|
|
Quickbar = <span class="string">'QuickbarValue'</span>,
|
|
JoinMessage = <span class="string">'JoinMessageValue'</span>
|
|
},
|
|
Statistics = {
|
|
Playtime = <span class="string">'PlaytimeValue'</span>,
|
|
JoinCount = <span class="string">'JoinCountValue'</span>
|
|
}
|
|
}
|
|
}
|
|
|
|
<span class="comment">-- If you used get_all on PlayerData.Settings this is what you would get:
|
|
</span>{
|
|
Cooldude2606 = {
|
|
Color = <span class="string">'ColorValue'</span>,
|
|
Quickbar = <span class="string">'QuickbarValue'</span>,
|
|
JoinMessage = <span class="string">'JoinMessageValue'</span>
|
|
}
|
|
}
|
|
|
|
<span class="comment">-- If you used get_all on PlayerData.Settings.Color this is what you would get:
|
|
</span>{
|
|
Cooldude2606 = <span class="string">'ColorValue'</span>
|
|
}</code></pre>
|
|
<!-- module usage end -->
|
|
|
|
<!-- module content header end -->
|
|
|
|
<!-- module section list start -->
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Dependencies">Dependencies</a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#utils.event">utils.event</a></td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Fields">Fields</a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#global.datastores">global.datastores</a></td>
|
|
<td class="summary">Save datastores in the global table</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Datastore_Manager">Datastore Manager </a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#metatable">metatable</a></td>
|
|
<td class="summary">Metatable used on datastores</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#connect">connect(datastoreName[, saveToDisk=false][, autoSave=false][, propagateChanges=false])</a></td>
|
|
<td class="summary">Make a new datastore connection, if a connection already exists then it is returned</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#combine">combine(datastoreName, subDatastoreName)</a></td>
|
|
<td class="summary">Make a new datastore that stores its data inside of another one</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#ingest">ingest(action, datastoreName, key, valueJson)</a></td>
|
|
<td class="summary">Ingest the result from a request, this is used through a rcon interface to sync data</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#debug">debug([datastoreName])</a></td>
|
|
<td class="summary">Debug, Use to get all datastores, or return debug info on a datastore</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#name_serializer">name_serializer(rawKey)</a></td>
|
|
<td class="summary">Commonly used serializer, returns the name of the object</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Datastore_Internal">Datastore Internal </a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#debug">debug()</a></td>
|
|
<td class="summary">Debug, Get the debug info for this datastore</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#raw_get">raw_get(key[, fromChild=false])</a></td>
|
|
<td class="summary">Internal, Get data following combine logic</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#raw_set">raw_set(key, value)</a></td>
|
|
<td class="summary">Internal, Set data following combine logic</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#serialize">serialize(rawKey)</a></td>
|
|
<td class="summary">Internal, Return the serialized key</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#write_action">write_action(action, key, value)</a></td>
|
|
<td class="summary">Internal, Writes an event to the output file to be saved and/or propagated</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Datastore_Local">Datastore Local </a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#combine">combine(subDatastoreName)</a></td>
|
|
<td class="summary">Create a new datastore which is stores its data inside of this datastore</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#set_serializer">set_serializer(callback)</a></td>
|
|
<td class="summary">Set a callback that will be used to serialize keys which aren't strings</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#set_metadata">set_metadata(tags)</a></td>
|
|
<td class="summary">Set metadata tags on this datastore which can be accessed by other scripts</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#get">get(key[, default])</a></td>
|
|
<td class="summary">Get a value from local storage, option to have a default value</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#set">set(key, value)</a></td>
|
|
<td class="summary">Set a value in local storage, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#increment">increment(key[, delta=1])</a></td>
|
|
<td class="summary">Increment the value in local storage, only works for number values, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#update">update(key, callback)</a></td>
|
|
<td class="summary">Use a function to update the value locally, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#remove">remove(key)</a></td>
|
|
<td class="summary">Remove a value locally and on the external source, works regardless of propagateChanges</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#get_all">get_all([callback])</a></td>
|
|
<td class="summary">Get all keys in this datastore, optional filter callback</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#update_all">update_all(callback)</a></td>
|
|
<td class="summary">Update all keys in this datastore using the same update function</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Datastore_External">Datastore External </a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#request">request(key)</a></td>
|
|
<td class="summary">Request a value from an external source, will trigger on_load when data is received</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#save">save(key)</a></td>
|
|
<td class="summary">Save a value to an external source, will trigger on_save before data is saved, save_to_disk must be set to true</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#unload">unload(key)</a></td>
|
|
<td class="summary">Save a value to an external source and remove locally, will trigger on_unload then on_save, save_to_disk is not required for on_unload</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#message">message(key, message)</a></td>
|
|
<td class="summary">Use to send a message over the connection, works regardless of saveToDisk and propagateChanges</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#save_all">save_all([callback])</a></td>
|
|
<td class="summary">Save all the keys in the datastore, optional filter callback</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#unload_all">unload_all([callback])</a></td>
|
|
<td class="summary">Unload all the keys in the datastore, optional filter callback</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Events">Events </a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#raise_event">raise_event(event_name, key[, value][, source])</a></td>
|
|
<td class="summary">Internal, Raise an event on this datastore</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#on_load">on_load</a></td>
|
|
<td class="summary">Register a callback that triggers when data is loaded from an external source, returned value is saved locally</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#on_save">on_save</a></td>
|
|
<td class="summary">Register a callback that triggers before data is saved, returned value is saved externally</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#on_unload">on_unload</a></td>
|
|
<td class="summary">Register a callback that triggers before data is unloaded, returned value is ignored</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#on_message">on_message</a></td>
|
|
<td class="summary">Register a callback that triggers when a message is received, returned value is ignored</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#on_update">on_update</a></td>
|
|
<td class="summary">Register a callback that triggers any time a value is changed, returned value is ignored</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<!-- module section list end -->
|
|
|
|
<br />
|
|
|
|
<!-- section start -->
|
|
<h3><span id="Dependencies" class="section-title"><a href="#Dependencies">Dependencies</a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#utils.event" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="utils.event">utils.event</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
|
|
<!-- parameters start -->
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Fields" class="section-title"><a href="#Fields">Fields</a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#global.datastores" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="global.datastores">global.datastores</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Save datastores in the global table</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Datastore_Manager" class="section-title"><a href="#Datastore_Manager">Datastore Manager </a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#metatable" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="metatable">metatable</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Metatable used on datastores</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Fields:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>__index</em></strong>
|
|
|
|
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>__newidnex</em></strong>
|
|
|
|
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>__call</em></strong>
|
|
|
|
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#connect" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="connect">connect(datastoreName[, saveToDisk=false][, autoSave=false][, propagateChanges=false])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Make a new datastore connection, if a connection already exists then it is returned</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>datastoreName</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The name that you want the new datastore to have, this can not have any whitespace
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>saveToDisk</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#boolean">boolean</a></span>)
|
|
|
|
When set to true, using the save method with write the data to datastore.pipe
|
|
|
|
(<em>default</em>: false)
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>autoSave</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#boolean">boolean</a></span>)
|
|
|
|
When set to true, using any method which modifies data will cause the data to be saved
|
|
|
|
(<em>default</em>: false)
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>propagateChanges</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#boolean">boolean</a></span>)
|
|
|
|
When set to true, using the save method will send the data to all other connected servers
|
|
|
|
(<em>default</em>: false)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
|
|
<span class="return-text">The new datastore connection that can be used to access and modify data in the datastore</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Connecting to the test datastore which will allow saving to disk
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>, <span class="keyword">true</span>) <span class="comment">-- saveToDisk
|
|
</span></code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#combine" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="combine">combine(datastoreName, subDatastoreName)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Make a new datastore that stores its data inside of another one</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>datastoreName</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The name of the datastore that will contain the data for the new datastore
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>subDatastoreName</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The name of the new datastore, this name will also be used as the key inside the parent datastore
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
|
|
<span class="return-text">The new datastore connection that can be used to access and modify data in the datastore</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Setting up a datastore which stores its data inside of another datastore
|
|
</span><span class="keyword">local</span> BarData = Datastore.combine(<span class="string">'ExampleData'</span>, <span class="string">'Bar'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#ingest" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="ingest">ingest(action, datastoreName, key, valueJson)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Ingest the result from a request, this is used through a rcon interface to sync data</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>action</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The action that should be done, can be: remove, message, propagate, or request
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>datastoreName</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The name of the datastore that should have the action done to it
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The key of that datastore that is having the action done to it
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>valueJson</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The json string for the value being ingested, remove does not require a value
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Replying to a data request
|
|
</span>Datastore.ingest(<span class="string">'request'</span>, <span class="string">'ExampleData'</span>, <span class="string">'TestKey'</span>, <span class="string">'Foo'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#debug" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="debug">debug([datastoreName])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Debug, Use to get all datastores, or return debug info on a datastore</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>datastoreName</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The name of the datastore to get the debug info of
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Get all the datastores
|
|
</span><span class="keyword">local</span> datastores = Datastore.<span class="global">debug</span>()</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Getting the debug info for a datastore
|
|
</span><span class="keyword">local</span> debug_info = Datastore.<span class="global">debug</span>(<span class="string">'ExampleData'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#name_serializer" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="name_serializer">name_serializer(rawKey)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Commonly used serializer, returns the name of the object</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>rawKey</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The raw key that will be serialized, this can be things like player, force, surface, etc
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
<span class="return-text">The name of the object that was passed</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Using the name serializer for your datastore
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:set_serializer(Datastore.name_serializer)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Datastore_Internal" class="section-title"><a href="#Datastore_Internal">Datastore Internal </a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#debug" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="debug">debug()</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Debug, Get the debug info for this datastore</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
|
|
<span class="return-text">The debug info for this datastore, contains stuff like parent, settings, children, etc</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Get the debug info for a datastore
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
<span class="keyword">local</span> debug_info = ExampleData:<span class="global">debug</span>()</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#raw_get" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="raw_get">raw_get(key[, fromChild=false])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Internal, Get data following combine logic</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The key to get the value of from this datastore
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>fromChild</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#boolean">boolean</a></span>)
|
|
|
|
If the get request came from a child of this datastore
|
|
|
|
(<em>default</em>: false)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
<span class="return-text">The value that was stored at this key in this datastore</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Internal, Get the data from a datastore
|
|
</span><span class="keyword">local</span> value = self:raw_get(<span class="string">'TestKey'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#raw_set" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="raw_set">raw_set(key, value)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Internal, Set data following combine logic</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The key to set the value of in this datastore
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>value</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The value that will be set at this key
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Internal, Set the value in a datastore
|
|
</span>self:raw_set(<span class="string">'TestKey'</span>, <span class="string">'Foo'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#serialize" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="serialize">serialize(rawKey)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Internal, Return the serialized key</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>rawKey</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that needs to be serialized, if it is already a string then it is returned
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
<span class="return-text">The key after it has been serialized</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Internal, Ensure that the key is a string
|
|
</span>key = self:serialize(key)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#write_action" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="write_action">write_action(action, key, value)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Internal, Writes an event to the output file to be saved and/or propagated</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>action</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The action that should be wrote to datastore.pipe, can be request, remove, message, save, propagate
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The key that the action is being preformed on
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>value</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The value that should be used with the action
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Write a data request to datastore.pipe
|
|
</span>self:write_action(<span class="string">'request'</span>, <span class="string">'TestKey'</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Write a data save to datastore.pipe
|
|
</span>self:write_action(<span class="string">'save'</span>, <span class="string">'TestKey'</span>, <span class="string">'Foo'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Datastore_Local" class="section-title"><a href="#Datastore_Local">Datastore Local </a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#combine" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="combine">combine(subDatastoreName)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Create a new datastore which is stores its data inside of this datastore</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>subDatastoreName</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The name of the datastore that will have its data stored in this datastore
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
|
|
<span class="return-text">The new datastore that was created inside of this datastore</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Add a new sub datastore
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
<span class="keyword">local</span> BarData = ExampleData:combine(<span class="string">'Bar'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#set_serializer" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="set_serializer">set_serializer(callback)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Set a callback that will be used to serialize keys which aren't strings</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The function that will be used to serialize non string keys passed as an argument
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Set a custom serializer, this would be the same as Datastore.name_serializer
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:set_serializer(<span class="keyword">function</span>(rawKey)
|
|
<span class="keyword">return</span> rawKey.name
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#set_metadata" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="set_metadata">set_metadata(tags)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Set metadata tags on this datastore which can be accessed by other scripts</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>tags</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
|
|
|
|
A table of tags that you want to set in the metadata for this datastore
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding metadata that could be used by a gui to help understand the stored data
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:set_metadata{
|
|
caption = <span class="string">'Test Data'</span>,
|
|
tooltip = <span class="string">'Data used for testing datastores'</span>,
|
|
<span class="global">type</span> = <span class="string">'table'</span>
|
|
}</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#get" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="get">get(key[, default])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Get a value from local storage, option to have a default value</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to get the value of, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>default</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The default value that will be returned if no value is found in the datastore
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Get a key from the datastore, the default will be deep copied if no value exists in the datastore
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
<span class="keyword">local</span> value = ExampleData:get(<span class="string">'TestKey'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#set" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="set">set(key, value)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Set a value in local storage, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to set the value of, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>value</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The value that you want to set for this key
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Set a value in the datastore, this will trigger on_update, if auto_save is true then will trigger save
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:set(<span class="string">'TestKey'</span>, <span class="string">'Foo'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#increment" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="increment">increment(key[, delta=1])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Increment the value in local storage, only works for number values, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to increment the value of, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>delta</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
The amount that you want to increment the value by, can be negative or a decimal
|
|
|
|
(<em>default</em>: 1)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Increment a value in a datastore, the value must be a number or nil, if nil 0 is used as the start value
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:increment(<span class="string">'TestNumber'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#update" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="update">update(key, callback)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Use a function to update the value locally, will trigger on_update then on_save, save_to_disk and auto_save is required for on_save</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to apply the update to, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The function that will be used to update the value at this key
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Using a function to update a value, if a value is returned then this will be the new value
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:increment(<span class="string">'TestKey'</span>, <span class="keyword">function</span>(key, value)
|
|
<span class="keyword">return</span> value..value
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#remove" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="remove">remove(key)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Remove a value locally and on the external source, works regardless of propagateChanges</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to remove locally and externally, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Remove a key locally and externally
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:remove(<span class="string">'TestKey'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#get_all" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="get_all">get_all([callback])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Get all keys in this datastore, optional filter callback</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The filter function that can be used to filter the results returned
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.5.html">table</a></span>)
|
|
<span class="return-text">All the data that is in this datastore, filtered if a filter was provided</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Get all the data in this datastore
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
<span class="keyword">local</span> data = ExampleData:get_all()</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Get all the data in this datastore, with a filter
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
<span class="keyword">local</span> data = ExampleData:get_all(<span class="keyword">function</span>(key, value)
|
|
<span class="keyword">return</span> <span class="global">type</span>(value) == <span class="string">'string'</span>
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#update_all" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="update_all">update_all(callback)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Update all keys in this datastore using the same update function</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The update function that will be applied to each key
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Get all the data in this datastore, with a filter
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:update_all(<span class="keyword">function</span>(key, value)
|
|
<span class="keyword">return</span> value..value
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Datastore_External" class="section-title"><a href="#Datastore_External">Datastore External </a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#request" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="request">request(key)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Request a value from an external source, will trigger on_load when data is received</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to request from an external source, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Request a key from an external source, on_load is triggered when data is received
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:request(<span class="string">'TestKey'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#save" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="save">save(key)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Save a value to an external source, will trigger on_save before data is saved, save_to_disk must be set to true</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to save to an external source, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Save a key to an external source, save_to_disk must be set to true for there to be any effect
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:save(<span class="string">'TestKey'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#unload" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="unload">unload(key)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Save a value to an external source and remove locally, will trigger on_unload then on_save, save_to_disk is not required for on_unload</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to unload from the datastore, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Unload a key from the datastore, get will now return nil and value will be saved externally if save_to_disk is set to true
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:unload(<span class="string">'TestKey'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#message" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="message">message(key, message)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Use to send a message over the connection, works regardless of saveToDisk and propagateChanges</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The key that you want to send a message over, must be a string unless a serializer is set
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>message</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The message that you want to send to other connected servers, or external source
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Send a message to other servers on this key, can listen for messages with on_message
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:message(<span class="string">'TestKey'</span>, <span class="string">'Foo'</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#save_all" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="save_all">save_all([callback])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Save all the keys in the datastore, optional filter callback</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The filter function that can be used to filter the keys saved
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Save all the data in this datastore
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
<span class="keyword">local</span> data = ExampleData:save_all()</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Save all the data in this datastore, with a filter
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:save_all(<span class="keyword">function</span>(key, value)
|
|
<span class="keyword">return</span> <span class="global">type</span>(value) == <span class="string">'string'</span>
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#unload_all" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="unload_all">unload_all([callback])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Unload all the keys in the datastore, optional filter callback</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The filter function that can be used to filter the keys unloaded
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Unload all the data in this datastore
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:unload_all()</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Unload all the data in this datastore, with a filter
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:unload_all(<span class="keyword">function</span>(key, value)
|
|
<span class="keyword">return</span> <span class="global">type</span>(value) == <span class="string">'string'</span>
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Events" class="section-title"><a href="#Events">Events </a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#raise_event" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="raise_event">raise_event(event_name, key[, value][, source])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Internal, Raise an event on this datastore</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>event_name</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The name of the event to raise for this datastore
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>key</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
The key that this event is being raised for
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>value</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
The current value that this key has, might be a deep copy of the value
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>source</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="http://lua-api.factorio.com/latest/Builtin-Types.html#string">string</a></span>)
|
|
|
|
Where this call came from, used to do event recursion so can be parent or child
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<strong>Returns:</strong>
|
|
<ul>
|
|
<li>
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
<span class="return-text">The value that is left after being passed through all the event handlers</span>
|
|
</li>
|
|
</ul>
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Internal, Getting the value that should be saved
|
|
</span>value = self:raise_event(<span class="string">'on_save'</span>, key, value)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#on_load" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="on_load">on_load</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Register a callback that triggers when data is loaded from an external source, returned value is saved locally</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-module-field-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The handler that will be registered to the on_load event
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding a handler to on_load, returned value will be saved locally, can be used to deserialize the value beyond a normal json
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:on_load(<span class="keyword">function</span>(key, value)
|
|
game.<span class="global">print</span>(<span class="string">'Test data loaded for: '</span>..key)
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#on_save" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="on_save">on_save</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Register a callback that triggers before data is saved, returned value is saved externally</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-module-field-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The handler that will be registered to the on_load event
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding a handler to on_save, returned value will be saved externally, can be used to serialize the value beyond a normal json
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:on_save(<span class="keyword">function</span>(key, value)
|
|
game.<span class="global">print</span>(<span class="string">'Test data saved for: '</span>..key)
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#on_unload" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="on_unload">on_unload</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Register a callback that triggers before data is unloaded, returned value is ignored</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-module-field-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The handler that will be registered to the on_load event
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding a handler to on_unload, returned value is ignored, can be used to clean up guis or local values related to this data
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:on_load(<span class="keyword">function</span>(key, value)
|
|
game.<span class="global">print</span>(<span class="string">'Test data unloaded for: '</span>..key)
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#on_message" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="on_message">on_message</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Register a callback that triggers when a message is received, returned value is ignored</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-module-field-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The handler that will be registered to the on_load event
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding a handler to on_message, returned value is ignored, can be used to receive messages from other connected servers without saving data
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:on_message(<span class="keyword">function</span>(key, value)
|
|
game.<span class="global">print</span>(<span class="string">'Test data message for: '</span>..key)
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#on_update" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="on_update">on_update</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Register a callback that triggers any time a value is changed, returned value is ignored</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-module-field-li">
|
|
|
|
<strong><em>callback</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
The handler that will be registered to the on_load event
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<strong>Usage:</strong>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Adding a handler to on_update, returned value is ignored, can be used to update guis or send messages when data is changed
|
|
</span><span class="keyword">local</span> ExampleData = Datastore.connect(<span class="string">'ExampleData'</span>)
|
|
ExampleData:on_update(<span class="keyword">function</span>(key, value)
|
|
game.<span class="global">print</span>(<span class="string">'Test data updated for: '</span>..key)
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
|
|
<!-- section end -->
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="footer container grid-1280">
|
|
<div class="divider divider-custom"></div>
|
|
<div class="footer-columns columns">
|
|
<div class="sidebar-footer column col-3 col-sm-12">
|
|
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc </a></i>
|
|
</div>
|
|
<div class="content-footer column col-9 col-sm-12">
|
|
<i>Last updated 2020-05-26 18:12:18 UTC</i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|