mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
1504 lines
59 KiB
HTML
1504 lines
59 KiB
HTML
|
|
|
|
<!doctype html>
|
|
<html class="no-js" lang="">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
|
<title>Store 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="#Tables"><span class="fragment-hashtag">#</span> Tables</a></li>
|
|
<li class="nav-item"><a href="#Fields"><span class="fragment-hashtag">#</span> Fields</a></li>
|
|
<li class="nav-item"><a href="#Store_Setup"><span class="fragment-hashtag">#</span> Store Setup </a></li>
|
|
<li class="nav-item"><a href="#Store_Data_Management"><span class="fragment-hashtag">#</span> Store Data Management </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"><div class="nav-item-block-inactive block"><a href="../core/Datastore.html"><span class="module-name-item">Datastore</span></a></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 active"><div class="nav-item-block-active block"><a href="../core/Store.html"><span class="module-name-item">Store</span></a><i class="icon icon-arrow-left icon-arrow-left-custom"></i></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/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/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>Data</h2>
|
|
<ul class="nav">
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../data/Alt-View.html"><span class="module-name-item">Alt-View</span></a></div></li>
|
|
<li class="nav-item"><div class="nav-item-block-inactive block"><a href="../data/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="../data/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="../data/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="../data/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="../data/Tag.html"><span class="module-name-item">Tag</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/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/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/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/Statistics.html"><span class="module-name-item">Statistics</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="#Tables"><span class="fragment-hashtag">#</span> Tables</a></li>
|
|
<li class="nav-item"><a href="#Fields"><span class="fragment-hashtag">#</span> Fields</a></li>
|
|
<li class="nav-item"><a href="#Store_Setup"><span class="fragment-hashtag">#</span> Store Setup </a></li>
|
|
<li class="nav-item"><a href="#Store_Data_Management"><span class="fragment-hashtag">#</span> Store Data Management </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>Store</em></strong></span> core</h2>
|
|
<p>Core Module - Store
|
|
- Used to store and watch for updates for values in the global table</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">-- Require the module and add a store with no keys
|
|
</span><span class="comment">-- Store with no keys does not need a serializer
|
|
</span><span class="keyword">local</span> Store = <span class="global">require</span> <span class="string">'expcore.store'</span> <span class="comment">--- @dep expcore.store
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()
|
|
|
|
<span class="comment">-- When the store is changed this function will trigger
|
|
</span>Store.watch(scenario_diffculty, <span class="keyword">function</span>(value)
|
|
game.<span class="global">print</span>(<span class="string">'The scenario diffculty has been set to '</span>..value)
|
|
<span class="keyword">end</span>)
|
|
|
|
Store.set(scenario_diffculty, <span class="string">'hard'</span>) <span class="comment">-- Set the value stored to 'hard'
|
|
</span>Store.get(scenario_diffculty) <span class="comment">-- Returns 'hard'
|
|
</span>Store.update(scenario_diffculty, <span class="keyword">function</span>(value) <span class="comment">-- Will set value to 'normal' if no value is present
|
|
</span> <span class="keyword">return</span> <span class="keyword">not</span> value <span class="keyword">and</span> <span class="string">'normal'</span>
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Require the module and add a store with keys
|
|
</span><span class="comment">-- Store with keys does not require a serializer but it can be helpful
|
|
</span><span class="keyword">local</span> Store = <span class="global">require</span> <span class="string">'expcore.store'</span> <span class="comment">--- @dep expcore.store
|
|
</span><span class="keyword">local</span> player_scores = Store.register(<span class="keyword">function</span>(player) <span class="comment">-- Use player name as the key
|
|
</span> <span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- When any key in the store is changed this function will trigger
|
|
</span>Store.watch(player_scores, <span class="keyword">function</span>(value, key, old_value)
|
|
game.<span class="global">print</span>(key..<span class="string">' now has a score of '</span>..value)
|
|
<span class="keyword">end</span>)
|
|
|
|
Store.set(player_scores, game.player, <span class="number">10</span>) <span class="comment">-- Set your score to 10
|
|
</span>Store.get(scenario_diffculty, game.player) <span class="comment">-- Returns 10
|
|
</span>Store.update(scenario_diffculty, game.player, <span class="keyword">function</span>(value) <span class="comment">-- Add 1 to your score
|
|
</span> <span class="keyword">return</span> value + <span class="number">1</span>
|
|
<span class="keyword">end</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="#Tables">Tables</a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#serializers">serializers</a></td>
|
|
<td class="summary">An array of the serializers that stores are using, key is store uids</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#watchers">watchers</a></td>
|
|
<td class="summary">An array of watchers that stores will trigger, key is store uids</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#file_paths">file_paths</a></td>
|
|
<td class="summary">An index used for debuging to find the file where different stores where registered</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="#uid">uid</a></td>
|
|
<td class="summary">The current highest uid that is being used, will not increase during runtime</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Store_Setup">Store Setup </a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#validate">validate(store[, key][, error_stack=1])</a></td>
|
|
<td class="summary">An error checking and serializing function for checking store uids and keys, note key is not required</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#register">register([serializer])</a></td>
|
|
<td class="summary">Required to create new stores and register an serializer to a store, serializer not required</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#watch">watch(store, watcher)</a></td>
|
|
<td class="summary">Register a watch function to a store that is called when the value in the store is changed, triggers for any key</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
<table class="section-content-list">
|
|
<thead>
|
|
<h3><a href="#Store_Data_Management">Store Data Management </a></h3>
|
|
<span></span>
|
|
</thead>
|
|
<tbody>
|
|
<tr>
|
|
<td class="name"><a href="#get">get(store[, key])</a></td>
|
|
<td class="summary">Used to retrive the current data that is stored, key is optional depending on if you are using them</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#clear">clear(store[, key])</a></td>
|
|
<td class="summary">Used to clear the data in a store, will trigger any watchers, key is optional depending on if you are using them</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#set">set(store[, key], value)</a></td>
|
|
<td class="summary">Used to set the data in a store, will trigger any watchers, key is optional depending on if you are using them</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#update">update(store[, key], updater)</a></td>
|
|
<td class="summary">Used to update the data in a store, use this with tables, will trigger any watchers, key is optional depending on if you are using them</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#map">map(store, updater)</a></td>
|
|
<td class="summary">Used to update all values that are in a store, similar to Store.update but acts on all keys at once, will trigger watchers for every key present</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#trigger">trigger(store[, key])</a></td>
|
|
<td class="summary">Used to trigger watcher functions, this may be used to trigger them if you did not use Store.update or Store.set</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="name"><a href="#raw_trigger">raw_trigger(store[, key][, value][, old_value])</a></td>
|
|
<td class="summary">Used to trigger watcher functions, the value and key are passed directly to the watchers regardless if the value is correct</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="Tables" class="section-title"><a href="#Tables">Tables</a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#serializers" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="serializers">serializers</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">An array of the serializers that stores are using, key is store uids</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>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#watchers" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="watchers">watchers</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">An array of watchers that stores will trigger, key is store uids</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>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#file_paths" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="file_paths">file_paths</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">An index used for debuging to find the file where different stores where registered</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="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="#uid" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="uid">uid</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">The current highest uid that is being used, will not increase during runtime</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-module-field-li">
|
|
|
|
<strong><em>uid</em></strong>
|
|
|
|
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
</ul>
|
|
|
|
<!-- parameters end -->
|
|
|
|
<!-- returns start -->
|
|
<!-- returns end -->
|
|
|
|
|
|
<!-- see also start -->
|
|
<!-- see also end -->
|
|
|
|
<!-- usage start -->
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Store_Setup" class="section-title"><a href="#Store_Setup">Store Setup </a></span></h3>
|
|
<dl class="section-body-container">
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#validate" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="validate">validate(store[, key][, error_stack=1])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">An error checking and serializing function for checking store uids and keys, note key is not required</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to check is valid
|
|
|
|
</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> or <span class="type">any</span></span>)
|
|
|
|
the key that you want to serialize or check is a string
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>error_stack</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the position in the stack relative to the current function (1) to raise this error on
|
|
|
|
(<em>default</em>: 1)
|
|
</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">if key is given and a serializer is registered, or key was already a string, then the key is returned</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">-- Registering a new store and checking that it is valid
|
|
</span><span class="comment">-- New store will use player names as the keys
|
|
</span><span class="keyword">local</span> player_scores = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- player_scores is a valid store and key will be your player name
|
|
</span><span class="keyword">local</span> key = Store.validate(player_scores, game.player)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#register" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="register">register([serializer])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Required to create new stores and register an serializer to a store, serializer not required</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>serializer</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
the function used to convert non string keys into strings to be used in the store
|
|
|
|
(<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.3.html">number</a></span>)
|
|
<span class="return-text">the uid for the new store that you have created, use this as the first param to all other functions</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">-- Creating a store with no serializer
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Creating a store which can take LuaPlayer
|
|
</span><span class="keyword">local</span> player_scores = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.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="#watch" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="watch">watch(store, watcher)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Register a watch function to a store that is called when the value in the store is changed, triggers for any key</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to watch for changes to
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>watcher</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 called when there is a change to the store
|
|
|
|
</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">-- Printing the changed value to all players, no keys
|
|
</span><span class="comment">-- Register the new store, we are not using keys so we dont need a serializer
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()
|
|
|
|
<span class="comment">-- Register the watcher so that when we change the value the message is printed
|
|
</span>Store.watch(scenario_diffculty, <span class="keyword">function</span>(value)
|
|
game.<span class="global">print</span>(<span class="string">'The scenario diffculty has been set to '</span>..value)
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Set a new value for the diffculty and see that it has printed to the game
|
|
</span>Store.set(scenario_diffculty, <span class="string">'hard'</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Printing the changed value to all players, with keys
|
|
</span><span class="comment">-- Register the new store, we are not using player names as the keys so it would be useful to accept LuaPlayer objects
|
|
</span><span class="keyword">local</span> player_scores = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Register the watcher so that when we change the value the message is printed
|
|
</span>Store.watch(player_scores, <span class="keyword">function</span>(value, key, old_value)
|
|
game.<span class="global">print</span>(key..<span class="string">' now has a score of '</span>..value)
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Set a new value for your score and see that it has printed to the game
|
|
</span>Store.set(player_scores, game.player, <span class="number">10</span>)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
</dl>
|
|
<h3><span id="Store_Data_Management" class="section-title"><a href="#Store_Data_Management">Store Data Management </a></span></h3>
|
|
<dl class="section-body-container">
|
|
<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(store[, key])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Used to retrive the current data that is stored, key is optional depending on if you are using them</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to get the value from
|
|
|
|
</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> or <span class="type">any</span></span>)
|
|
|
|
the key that you want to get the value of, must be a string unless you have a serializer
|
|
|
|
(<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 data that is stored</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">-- Getting the value of a store with no keys
|
|
</span><span class="comment">-- Register the new store, we are not using keys so we dont need a serializer
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()
|
|
|
|
<span class="comment">-- Get the current diffculty for the scenario
|
|
</span><span class="keyword">local</span> diffculty = Store.get(scenario_diffculty)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Getting the data from a store with keys
|
|
</span><span class="comment">-- Register the new store, we are not using player names as the keys so it would be useful to accept LuaPlayer objects
|
|
</span><span class="keyword">local</span> player_scores = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Get your current score
|
|
</span><span class="keyword">local</span> my_score = Store.get(player_scores, game.player)
|
|
|
|
<span class="comment">-- Get all scores
|
|
</span>lcoal scores = Store.get(player_scores)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#clear" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="clear">clear(store[, key])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Used to clear the data in a store, will trigger any watchers, key is optional depending on if you are using them</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to clear
|
|
|
|
</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> or <span class="type">any</span></span>)
|
|
|
|
the key that you want to clear, must be a string unless you have a serializer
|
|
|
|
(<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">-- Clear a store which does not use keys
|
|
</span><span class="comment">-- Register the new store, we are not using keys so we dont need a serializer
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()
|
|
|
|
<span class="comment">-- Clear the scenario diffculty
|
|
</span>Store.clear(scenario_diffculty)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Clear data that is in a store with keys
|
|
</span><span class="comment">-- Register the new store, we are not using player names as the keys so it would be useful to accept LuaPlayer objects
|
|
</span><span class="keyword">local</span> player_scores = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Clear your score
|
|
</span>Store.clear(player_scores, game.player)
|
|
|
|
<span class="comment">-- Clear all scores
|
|
</span>Store.clear(player_scores)</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(store[, key], value)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Used to set the data in a store, will trigger any watchers, key is optional depending on if you are using them</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to set
|
|
|
|
</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> or <span class="type">any</span></span>)
|
|
|
|
the key that you want to set, must be a string unless you have a serializer
|
|
|
|
(<em>optional</em>)
|
|
</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
|
|
|
|
</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">-- Setting a store which does not use keys
|
|
</span><span class="comment">-- Register the new store, we are not using keys so we dont need a serializer
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()
|
|
|
|
<span class="comment">-- Set the new scenario diffculty
|
|
</span>Store.set(scenario_diffculty, <span class="string">'hard'</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Set data in a store with keys
|
|
</span><span class="comment">-- Register the new store, we are not using player names as the keys so it would be useful to accept LuaPlayer objects
|
|
</span><span class="keyword">local</span> player_scores = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Set your current score
|
|
</span>Store.set(player_scores, game.player, <span class="number">10</span>)
|
|
|
|
<span class="comment">-- Set all scores, note this might not have much use
|
|
</span>Store.set(player_scores, {
|
|
[game.player.name] = <span class="number">10</span>,
|
|
[<span class="string">'SomeOtherPlayer'</span>] = <span class="number">0</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(store[, key], updater)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Used to update the data in a store, use this with tables, will trigger any watchers, key is optional depending on if you are using them</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to update
|
|
|
|
</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> or <span class="type">any</span></span>)
|
|
|
|
the key that you want to update, must be a string unless you have a serializer
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>updater</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.6.html">function</a></span>)
|
|
|
|
the function which is called to make changes to the value, such as changing table keys, if a value is returned it will replace the current value in the store
|
|
|
|
</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">-- Incrementing a global score
|
|
</span><span class="comment">-- Because we are only going to have one score so we will not need keys or a serializer
|
|
</span><span class="keyword">local</span> game_score = Store.register()
|
|
|
|
<span class="comment">-- Setting a default value
|
|
</span>Store.set(game_score, <span class="number">0</span>)
|
|
|
|
<span class="comment">-- We now will update the game score by one, we return the value so that it is set as the new value in the store
|
|
</span>Store.update(game_score, <span class="keyword">function</span>(value)
|
|
<span class="keyword">return</span> value + <span class="number">1</span>
|
|
<span class="keyword">end</span>)</code></pre>
|
|
<pre class="code" data-lang="Lua"><code><span class="comment">-- Updating keys in a table of data
|
|
</span><span class="comment">-- Register the new store, we are not using player names as the keys so it would be useful to accept LuaPlayer objects
|
|
</span><span class="keyword">local</span> player_data = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Setting a default value for your player, used to show the table structure
|
|
</span>Store.set(player_data, game.player, {
|
|
group = <span class="string">'Admin'</span>,
|
|
role = <span class="string">'Owner'</span>,
|
|
show_group_config = <span class="keyword">false</span>
|
|
})
|
|
|
|
<span class="comment">-- Updating the show_group_config key in your player data, note that it would be harder to call set every time
|
|
</span><span class="comment">-- We do not need to return anything in this case as we are not replacing all the data
|
|
</span>Store.update(player_data, game.player, <span class="keyword">function</span>(data)
|
|
data.show_group_config = <span class="keyword">not</span> data.show_group_config
|
|
<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="#map" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="map">map(store, updater)</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Used to update all values that are in a store, similar to Store.update but acts on all keys at once, will trigger watchers for every key present</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to map
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>updater</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 is called on every key in this store
|
|
|
|
</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">-- Updating keys in a table of data
|
|
</span><span class="comment">-- Register the new store, we are not using player names as the keys so it would be useful to accept LuaPlayer objects
|
|
</span><span class="keyword">local</span> player_data = Store.register(<span class="keyword">function</span>(player)
|
|
<span class="keyword">return</span> player.name
|
|
<span class="keyword">end</span>)
|
|
|
|
<span class="comment">-- Setting a default value for your player, used to show the table structure
|
|
</span>Store.set(player_data, game.player, {
|
|
group = <span class="string">'Admin'</span>,
|
|
role = <span class="string">'Owner'</span>,
|
|
show_group_config = <span class="keyword">false</span>
|
|
})
|
|
|
|
<span class="comment">-- Updating the show_group_config key for all players, note that it would be harder to call set every time
|
|
</span><span class="comment">-- We do not need to return anything in this case as we are not replacing all the data
|
|
</span><span class="comment">-- We also have access to the current key being updated if needed
|
|
</span>Store.map(player_data, <span class="keyword">function</span>(data, key)
|
|
data.show_group_config = <span class="keyword">not</span> data.show_group_config
|
|
<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="#trigger" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="trigger">trigger(store[, key])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Used to trigger watcher functions, this may be used to trigger them if you did not use Store.update or Store.set</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to trigger
|
|
|
|
</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> or <span class="type">any</span></span>)
|
|
|
|
the key that you want to trigger, must be a string unless you have a serializer
|
|
|
|
(<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">-- Faking the update to a store
|
|
</span><span class="comment">-- The type of store we use does not really matter for this as long as you pass it what you watchers are expecting
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()
|
|
|
|
<span class="comment">-- Trigger the watchers with a fake change of diffculty
|
|
</span>Store.trigger(scenario_diffculty)</code></pre>
|
|
<!-- usage end -->
|
|
|
|
</dd>
|
|
<dt>
|
|
<div class="divider divider-custom"></div>
|
|
<div class="block section-item-header">
|
|
<a href="#raw_trigger" class="fragment-hashtag">#</a>
|
|
<span class="section-item-title" id="raw_trigger">raw_trigger(store[, key][, value][, old_value])</span>
|
|
</div>
|
|
</dt>
|
|
<dd>
|
|
<div class="section-item-body">
|
|
|
|
<p class="section-item-summary">Used to trigger watcher functions, the value and key are passed directly to the watchers regardless if the value is correct</p>
|
|
<p class="section-item-description"></p>
|
|
|
|
<!-- parameters start -->
|
|
<strong>Parameters:</strong>
|
|
|
|
<ul>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>store</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><a class="type" href="https://www.lua.org/pil/2.3.html">number</a></span>)
|
|
|
|
the uid of the store that you want to trigger
|
|
|
|
</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> or <span class="type">any</span></span>)
|
|
|
|
the key that you want to trigger, must be a string unless you have a serializer
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>value</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
the new value that is at this key or store, passed directly to the watcher
|
|
|
|
(<em>optional</em>)
|
|
</li>
|
|
|
|
|
|
|
|
|
|
|
|
<li class="section-subitem-li">
|
|
|
|
<strong><em>old_value</em></strong>
|
|
|
|
<strong> : </strong>
|
|
|
|
(<span class="types"><span class="type">any</span></span>)
|
|
|
|
the old value that was at this key or store often the same if value is a table, passed directly to the watcher
|
|
|
|
(<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">-- Triggering a manule call of the watchers
|
|
</span><span class="comment">-- The type of store we use does not really matter for this as long as you pass it what you watchers are expecting
|
|
</span><span class="keyword">local</span> scenario_diffculty = Store.register()
|
|
|
|
<span class="comment">-- Trigger the watchers with a fake change of diffculty
|
|
</span><span class="comment">-- This is mostly used internally but it can be useful in other cases
|
|
</span>Store.raw_trigger(scenario_diffculty, <span class="keyword">nil</span>, <span class="string">'normal'</span>, <span class="string">'normal'</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-30 15:28:02 UTC</i>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|