World Storage

[DEPRECATED] Allows saving and loading data to the world folder, and offers an alternative to global settings

Deprecated API / Library

Download (4 KB)

How do I install this?

Usage

DEPRECATED: Avoid using for new projects. Mod storage is faster and more robust. This API is only good for if you need to be able to easily access the data in the world folder, but other than that it's a slower, less robust version of the builtin minetest.get_mod_storage. That is, if you specifically want to be able to edit the files in the world folder, this is fine, but for literally everything else, use modstorage and roll your own persistence using that. For world settings, use aom_settings which is a lighter weight alternative, yet comes with a formspec so you can edit world settings in game on the fly as a moderator with server privs.

To get a key from storage:

world_storage.get(domain, key)

To save a key to storage:

world_storage.set(domain, key, val, flags)

As a world settings solution

You can also use the chat command to set custom settings that can be used by your mods instead of the global minetest server settings. Note this cannot affect domains other than "_ws", and this is its intended and only valid use. The first param is n for number or s for string / raw.

wset n key 389.2
wset s key some string of letters, even with spaces
wset [anything] key nil -- deletes a key

Then, these values can be accessed with wset and wget.

local value = world_storage.wget("my_mod:setting_name")
-- e.g.
local reload_time = world_storage.wget("pmb_muskets:reload_speed")

To make sure you don't get nil or have to check for it all the time, you can do this with all of your stored variables:

if world_storage.wget("pmb_muskets:reload_speed") == nil then
    world_storage.wset("pmb_muskets:reload_speed", "my_default_value")
end

Parameters

domain

This is the filename used for the saving of the data. Each domain is a list - world_storage.domain[domainname] = {}. You can overwrite keys from other mods with this, so choose a unique name, such as the name of your mod.

key

The key name / variable name you want to save

val

The arbitrary data you want to save

flags

Only one flag implemented so far: - timeout : used to tell the system how long between autosaves

Notes on usage

The system will autosave regularly if there are changes made, and this is important to note. If you are saving a lot of data, this is not the right system to use. Instead, construct your own system to handle your specific use case. For example, if you need to store several kilobytes of data regularly, this is not how you do it.

Reviews

Review

Do you recommend this mod?

  • No reviews, yet.